import java.util.*; import java.math.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); boolean[] a = new boolean[3]; a[sc.nextInt()-1] = true; int m = sc.nextInt(); for(int i = 0; i < m; i++) { int p = sc.nextInt()-1; int q = sc.nextInt()-1; boolean tmp = a[p]; a[p] = a[q]; a[q] = tmp; } int num = 0; for(int i = 0; i < 3; i++) { if(a[i]) num = i+1; } System.out.println(num); } }