n = int(input()) m = int(input()) s = [0, 0, 0] s[n-1] = 1 for i in range(m): p =input().split() s[int(p[0])-1],s[int(p[1])-1] = s[int(p[1])-1],s[int(p[0])-1] print(s.index(1)+1)