var
f,x,y,z:array[0..7001] of int64;
n,m,i,min:longint;
function check:boolean;
var
j,i:longint;
begin
f[1]:=0; min:=maxlongint;
for j:=1 to n do
for i:=1 to m do
if (f[y[i]]<f[x[i]]-z[i]) then begin
f[y[i]]:=f[x[i]]-z[i];
end;
for i:=1 to m do
if (f[y[i]]<f[x[i]]-z[i]) then exit(false);
exit(true);
end;
begin
assign(input,'work.in'); reset(input);
assign(output,'work.out'); rewrite(output);
read(n,m); for i:=1 to n do f[i]:=-100000;
for i:=1 to m do read(x[i],y[i],z[i]);
{for i:=1 to n do begin
x[i+m]:=5001; y[i+m]:=i; z[i+m]:=0;
end;}
if check then begin
for i:=1 to n do if f[i]<min then min:=f[i];
for i:=1 to n do writeln(f[i]-min,' ');
end else writeln('NO SOLUTION');
end.