def main():

  change_lists = []
  point = int(input())
  kaisu = int(input())
  for _ in range(kaisu):
    change_lists.append(list(map(int, input().split())))
  for change_list in change_lists:
    if change_list[0] == point:
      point = change_list[1]
    else:
      continue
  print(point)

if __name__ == '__main__':
  main()