Program sl;
var
dist,s:array[0..1000]of longint;
b,e,w:array[0..5000]of longint;
n,m,j,i,t:longint;
function bellman:boolean;
begin
for j:=1 to n-1 do
for i:=1 to m do
if dist[e[i]]>dist[b[i]]+w[i]
then dist[e[i]]:=dist[b[i]]+w[i];
for i:=1 to m do
if dist[e[i]]>dist[b[i]]+w[i]
then exit(false);
exit(true);
end;
begin
assign(input,'work.in');
assign(output,'work.out');
reset(input);
rewrite(output);
read(n,m);
for i:=1 to n do
dist[i]:=0;
for i:=1 to m do
read(b[i],e[i],w[i]);
if bellman
then begin
for i:=1 to n do
if t>dist[i] then t:=dist[i];
for i:=1 to n do
write(dist[i]-t,' ')
end
else writeln('NO SOLUTION');
close(input);
close(output);
end.