#include
#include
#include
#include
#define N 110
using namespace std;
int n,ans(0);
int w[N][N],dis[N];
bool f[N]={0};
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
dis[i]=0x7fffffff;
for (int j=1;j<=n;j++)
{
scanf("%d",&w[i][j]);
if (w[i][j]==0) w[i][j]=0x7fffffff;
}
}
dis[0]=0x7fffffff;
dis[1]=0;
for (int i=1;i<=n;i++)
{
int k=0;
for (int j=1;j<=n;j++)
if (!f[j]&&dis[j]j;
f[k]=1;
for (int j=1;j<=n;j++)
if (!f[j]&&dis[j]>w[k][j]) dis[j]=w[k][j];
}
for (int i=1;i<=n;i++) ans+=dis[i];
cout<endl;
return 0;
}