import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); int[] arr = new int[3]; arr[N - 1] = 1; for(int i = 0; i < M; i++) { int p = sc.nextInt() - 1; int q = sc.nextInt() - 1; int temp = arr[p]; arr[p] = arr[q]; arr[q] = temp; } int ans = 0; for(int i = 0; i < 3; i++) { if(arr[i] == 1) ans = i + 1; } System.out.println(ans); } }