type point=^note;
note=record
next:point;
v,num:longint;
end;
var tt,head,tail,x,y,z,n,m,i,j,k:longint;
vis:array[0..1000] of boolean;
a:array[0..1000] of note;
save:array[1..1000] of boolean;
d:array[0..1000] of longint;
h:array[1..1001] of longint;
p,q:point;
gg:array[1..1000] of longint;
procedure init;
begin
readln(n,m);
for i:=0 to n do
d[i]:=-maxlongint;
for i:=1 to m do
begin
readln(x,y,z);
save[x]:=true;
save[y]:=true;
new(p);
p^.num:=y;
p^.v:=-z;
p^.next:=a[x].next;
a[x].next:=p;
inc(a[x].num);
end;
for i:=1 to n do
begin
new(p);
p^.next:=a[0].next;
p^.num:=i;
p^.v:=0;
a[0].next:=p;
inc(a[0].num);
end;
for i:=1 to n do vis[i]:=false;
vis[0]:=true;
d[0]:=0;
h[1]:=0;
head:=1;
tail:=1;
while (head<>tail)or(vis[0]=true) do
begin
tt:=h[head];
p:=a[tt].next;
for i:=1 to a[tt].num do
begin
if d[tt]+p^.v>d[p^.num] then
begin
d[p^.num]:=d[tt]+p^.v;
if not(vis[p^.num]) then
begin
if tail+1 > 1001 then tail:=tail-1000 else inc(tail);
h[tail]:=p^.num;
inc(gg[p^.num]);
if gg[p^.num]>n then begin writeln('SOMEONE LAY!');close(output);halt;end;
vis[p^.num]:=true;
end;
end;
q:=p^.next;
p:=q;
end;
vis[tt]:=false;
if head>1000 then head:=head-1000 else head:=head+1;
end;
for i:=1 to n do
if save[i] then write(d[i],' ') else write(-1);
end;
begin
assign(input,'ExamStat.in');
assign(output,'ExamStat.out');
reset(input);
rewrite(output);
init;
close(output);
end.