var
i,j,k,n,min,ans:longint;
f:array[1..100] of boolean;
a:array[1..100,1..100] of longint;
d:array[1..100] of longint;
procedure Prim;
begin
fillchar(f,sizeof(f),false);
for i:=1 to n do d[i]:=a[1,i];
f[1]:=true;
ans:=0;
for i:=2 to n do
begin
min:=maxlongint div 2;
for j:=1 to n do
if (not f[j]) and (d[j]<min) then
begin min:=d[j]; k:=j; end;
inc(ans,d[k]);
f[k]:=true;
for j:=1 to n do
if (not f[j]) and (a[k,j]<d[j]) then d[j]:=a[k,j];
end;
writeln(ans);
end;
begin
assign(input,'agrinet.in');
reset(input);
assign(output,'agrinet.out');
rewrite(output);
readln(n);
for i:=1 to n do begin
for j:=1 to n do
read(a[i,j]); readln; end;
Prim;
close(input);
close(output);
end.