n = gets.chomp.to_i m = gets.chomp.to_i cups = Array.new(4, false) cups[n] = true m.times do p_, q_ = gets.chomp.split(" ").map(&:to_i) cups[p_], cups[q_] = cups[q_], cups[p_] end puts cups.index(true)