import java.util.Scanner; class N026{ public static void main(String args[]){ Scanner s = new Scanner(System.in); int n = s.nextInt(); int m = s.nextInt(); for(int i = 0; i < m; i++){ int p = s.nextInt(); int q = s.nextInt(); if(p == n){ n = q; }else if(q == n){ n = p; } } System.out.println(n); } }