x=gets.to_i gets $<.map{|s|p,q=s.split.map &:to_i;(x==p||x==q)&&x^=p^q} p x