type mch=record x,y:integer end;
var fi:text;
f:array[1..1001,1..1001] of longint;
a :array[1..1001,0..1001] of integer;
c:array[1..1001,1..1001] of integer;
verymax,max,cap,ns,x1,n,i,m,j,k,eps,s,t,p,q,llant:integer;
lant,viz,cq,zzz:array[1..1001] of integer;
sol:array[1..1001] of integer;
vec:array[1..1001] of mch;
procedure citire;
begin
assign(fi,'critice.in'); reset(Fi);
readln(fi,n,m);
for k:=1 to m do
begin
readln(fi,i,j,cap);
inc(a[i,0]); a[i,a[i,0]]:=j;
inc(a[j,0]); a[j,a[j,0]]:=i;
c[i,j]:=cap;
c[j,i]:=cap;
vec[k].x:=i; vec[k].Y:=j;
end;
close(Fi);
end;
function bf:boolean;
var i,vf:integer;
begin
fillchar(viz,sizeof(viz),0);
viz[s]:=-1;
cq[1]:=s; p:=1; q:=1;
while (q<=p)and(viz[t]=0) do
begin
vf:=cq[q];
for i:=1 to n do
if (c[vf,i]>0)and(viz[i]=0) and
( (f[vf,i]<c[vf,i]) or (f[i,vf]>0)) then
begin
inc(p);
cq[p]:=i;
viz[i]:=vf;
if i=t then break;
end;
inc(q);
end;
if viz[t]<>0 then
begin
bf:=true;
eps:=maxint;
llant:=0; i:=t;
while i<>-1 do
begin
if viz[i]<>-1 then if (f[viz[i],i]>=0)and(c[viz[i],i]-f[viz[i],i]<eps) then
eps:=c[viz[i],i]-f[viz[i],i]
else if (f[i,viz[i]]>0)and(f[i,viz[i]]<eps) then eps:=f[i,viz[i]];
inc(llant);
lant[llant]:=i;
i:=viz[i];
end;
end else bf:=false;
end;
procedure flux_max;
var i:integer;
begin
fillchar(f,sizeof(f),0);
while bf do
begin
for i:=llant downto 2 do
if (f[lant[i],lant[i-1]]<=0) then
begin
inc(f[lant[i],lant[i-1]],eps);
f[lant[i-1],lant[i]]:=-f[lant[i],lant[i-1]];
end
else
begin
dec(f[lant[i-1],lant[i]],eps);
f[lant[i],lant[i-1]]:=-f[lant[i-1],lant[i]];
end;
inc(max,eps);
end;
end;
procedure afis;
begin
assign(fi,'critice.out'); rewrite(Fi);
writeln(fi,ns);
for i:=1 to ns do writeln(Fi,sol[i]);
close(fi);
end;
begin
citire;
max:=0;
s:=1; t:=n;
flux_max;
verymax:=max;
for i:=1 to m do
begin
max:=0;
inc(c[vec[i].x,vec[i].y]);
inc(c[vec[i].y,vec[i].x]);
flux_max;
if max>verymax then
begin
inc(ns);
sol[ns]:=i;
end;
dec(c[vec[i].x,vec[i].y]);
dec(c[vec[i].y,vec[i].x]);
end;
afis;
end.