def main(): n = int(input()) m = int(input()) l = [i == n for i in range(1, 3 + 1)] for _ in range(m): p, q = map(int, input().split()) p -= 1 q -= 1 l[p], l[q] = l[q], l[p] print(l.index(True) + 1) if __name__ == '__main__': main()