n = int(input()) m = int(input()) cup = [] for x in [1,2,3]: if x == n: cup.append(True) else: cup.append(False) seq = [] for _ in range(m): seq.append(list(map(int,input().split()))) for u in seq: frm = u[0]-1; f = cup[frm] to = u[1]-1; t = cup[to] cup[to] = f cup[frm] = t for i,c in enumerate(cup,1): if c: print(i)