n, m = map(int, input().split())
my_dict = {}
for j in range(m):
    aj, bj = map(int, input().split())
    my_dict[aj] = bj

bjs = [bj for aj, bj in my_dict.items() if aj <= n]
if bjs:  # 判断是否非空
    print(f"{n-max(bjs)}")
else:
    print(n)