n, m = map(int,input().split())
dic = {}
for i in range(m):
    k,v = map(int,input().split())
    dic[k] = v
new_dic = sorted(dic.items(),key = lambda x:(-x[1],x[0]))
out = n
for i in range(m):
    if n>=new_dic[i][0]:
        out = n - new_dic[i][1]
        break
print(out)