# coding: utf-8 n = int(input()) - 1 m = int(input()) cups = [False] * 3 cups[n] = True for i in range(m): p, q = [int(j) - 1 for j in input().split()] tmp = cups[p] cups[p] = cups[q] cups[q] = tmp print(cups.index(True) + 1)