import java.util.*; public class Run { public static void main (String arg[]) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int M = scan.nextInt(); if (N < 1||N > 3||M < 1||M > 200) System.exit(1); int P,Q; for (int i = 0; i < M; i++) { P = scan.nextInt(); Q = scan.nextInt(); if (P < 1||P > 3||Q < 1||Q > 3||P==Q) System.exit(1); if (P==N) N = Q; else if (Q==N) N = P; } System.out.println(N); } }