import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] t = new int[3]; t[sc.nextInt() - 1] = 1; int n = sc.nextInt(), a, b, tmp; for (int i = 0; i < n; i++) { a = sc.nextInt() - 1; b = sc.nextInt() - 1; tmp = t[a]; t[a] = t[b]; t[b] = tmp; } for (int i = 0; i < 3; i++) { if (t[i] == 1) { System.out.println(i + 1); return; } } } }