n = int(input()) m = int(input()) caps = [True, False, False] for _ in range(m): pi, qi = map(int, input().split()) pi -= 1 qi -= 1 caps[pi], caps[qi] = caps[qi], caps[pi] for i in range(len(caps)): if caps[i]: print(i + 1) exit()