n=gets.to_i
m=gets.to_i
e=Hash.new{|h,k|h[k]=[]}
w=(0..n).map{[]}
l=(0..n).map{[]}
r=[0]*(n+1)
(1..m).map{i,j=gets.split.map(&:to_i);e[i][j]=-1;e[j][i]=1;w[i]<<j;l[j]<<i;[i,j]}

s=1
while w[s][0]
s=w[s][0]
end

while l[s][0]
s=l[s][0]
end

t=[s]
c=0
while t!=[]
c+=1
t=t.flat_map{|i|r[i]=c;w[i]}
end


p *(1..n).sort_by{|i|r[i]},c<n ?1:0