n, m = gets.split.map(&:to_i)

@child = Array.new(n+1) {|i| i}
parent = Array.new(n+1, 0)
calc =->x{x == @child[x] ? x : @child[x] = calc[@child[x]]}

(n-1+m).times do |i|
    a, b = gets.split.map(&:to_i)

    ca = calc[a]
    cb = calc[b]

    next if ca == cb
    parent[b] = a
    @child[a] = b
end

1.upto(n) {|i| p parent[i]}