#include<cstdio>
#include<iostream>
#include<cstring>//Prim算法
#define N 110
using namespace std;
int g[N][N],minn[N],vis[N],n;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
scanf("%d",&g[i][j]);
}
}
memset(minn,0x7f,sizeof minn);
minn[1]=0;
for(int i=1;i<=n;i++){
int k=0;
for(int j=1;j<=n;j++){
if(!vis[j]&&(minn[j]<minn[k])){
k=j;
}
}
vis[k]=1;
for(int j=1;j<=n;j++){
if(!vis[j]&&(g[k][j]<minn[j])){
minn[j]=g[k][j];
}
}
}
int tot=0;
for(int i=1;i<=n;i++){
tot+=minn[i];
}
printf("%d\n",tot);
return 0;
}