import java.util.Scanner; public class No26 { public static void main(String[] args) { //シャッフルゲーム Scanner s = new Scanner(System.in); int N = Integer.parseInt(s.nextLine()) , M = Integer.parseInt(s.nextLine()); int P , Q; for(int i = 0;i < M;i++) { P = s.nextInt(); Q = s.nextInt(); if(P == N | Q == N) { N = P + Q - N; } s.nextLine(); } s.close(); System.out.println(N); } }