var
now,min,i,j,x,y,z,n,m:longint;
a:array[0..1000,0..1000]of longint;
begin
assign(input,'t2bb.in'); reset(input);
assign(output,'t2bb.out'); rewrite(output);
readln(n,m);
for i:=1 to m do
begin
readln(x,y,z);
a[x,y]:=z;
a[y,x]:=z;
end;
min:=maxlongint;
for i:=0 to n-1 do
begin
now:=0;
for j:=0 to n-1 do inc(now,a[i,j]);
if now<min then min:=now;
end;
writeln(min);
close(input);
close(output);
end.