w = gets.to_i
n = gets.to_i

horizon_bars = []
n.times do
  horizon_bars << gets.split(",").map(&:to_i)
end
p horizon_bars

1.upto(w) do |i|
  horizon_bars.reverse_each do |bar|
    source =  bar.index(i)
    i = bar[(source+1)%2] if source
  end
  puts i
end