package me.yukicoder.lv1; import java.util.Scanner; public class No0026 { public static void main(String[] args) { try (Scanner sc = new Scanner(System.in);) { int N = sc.nextInt(); int M = sc.nextInt(); boolean[] cup = new boolean[3]; cup[N - 1] = true;// 最初に○印が付いているカップ for (int i = 0; i < M; i++) { int p = sc.nextInt(); int q = sc.nextInt(); exchange(cup, p, q); } System.out.println(cnt(cup)); } } static void exchange(boolean[] cup, int p, int q) { boolean boo = cup[p - 1]; cup[p - 1] = cup[q - 1]; cup[q - 1] = boo; } static int cnt(boolean[] cup) { int cnt; for (cnt = 0; cnt < cup.length; cnt++) { if (cup[cnt]) break; } return cnt + 1; } }