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[0]] << a[1]
  inv_hash << a[1] #[a[1]] << a[0]
end

NODE_WEIGHT = Array.new(nm[0]+1)

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

queue = [[start, 0, 0]]

while queue != []
  k = queue.pop
  next if NODE_WEIGHT[k[0]] && NODE_WEIGHT[k[0]][0] < k[1]
  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|
    #if !NODE_WEIGHT[i] || NODE_WEIGHT[k[0]][0] < k[1]
    #NODE_WEIGHT[i] = [k[1]+1, k[0]]
    queue.push [i, k[1] + 1, k[0]]
  end
end

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