import random
random.seed("xiaowucone")
n, ret = (int(x) for x in input().split())
skip = True
for _ in range(n):
  a, b = (int(x) for x in input().split())
  if a <= ret <= b and random.random() < 0.9999:
    ret += 1
print(ret)