hash = Hash.new{|h,k| h[k] = []}
inv_hash = Hash.new{|h,k| h[k] = []}

nm = gets.chomp.split(" ").map(&:to_i)

for i in 0..nm[0]-2+nm[1]
  a = gets.chomp.split(" ").map(&:to_i)
  #hash[a[1]] = [] if !hash[a[1]]
  hash[a[0]] << a[1]
  inv_hash[a[1]] << a[0]
end

NODE_WEIGHT = {}

start = (hash.keys - inv_hash.keys)[0]

queue = [[start, 0, 0]]

while queue != []
  k = queue.pop
  NODE_WEIGHT[k[0]] = [k[1], k[2]] if !NODE_WEIGHT[k[0]] || NODE_WEIGHT[k[0]][0] < k[1]
  hash[k[0]].each do |i|
    queue.push [i, k[1] + 1, k[0]]
  end
end

#p NODE_WEIGHT

#final = Array.new(nm[0]+nm[1]-2)
#inv_hash.to_a.each do |t|
#  criteria = NODE_WEIGHT[t[0]]
#  t[1].each do |k|
#    final[t[0]] = k if NODE_WEIGHT[k][0] + 1 == criteria
#  end
#end

for i in 1..nm[0]
  puts NODE_WEIGHT[i][1]
end