import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); boolean[] hasBall = new boolean[4]; hasBall[sc.nextInt()] = true; int m = sc.nextInt(); for (int i = 0; i < m; i++) { int left = sc.nextInt(); int right = sc.nextInt(); boolean tmp = hasBall[left]; hasBall[left] = hasBall[right]; hasBall[right] = tmp; } for (int i = 1; i < 4; i++) { if (hasBall[i]) { System.out.println(i); return; } } } }