class A def initialize n = gets.chomp.to_i m = gets.chomp.to_i cup = [0,0,0,0] cup[n] = 1 m.times do p, q = gets.chomp.split(' ').map(&:to_i) cup[p], cup[q] = cup[q], cup[p] end puts cup.index(1) end end A.new