#数据输入及初始化
l, m = map(int,input().split())
pds = [list(map(int,input().split())) for _ in range(m)]
#施工区域区间合并
pds.sort(key=lambda x:(x[0],x[1]))
res, cnt = [], pds[0]
for x in pds[1:]:
    if cnt[0]<=x[0]<=cnt[1]:
        cnt[1] = max(cnt[1],x[1])
    if x[0]>cnt[1]:
        res += [cnt]
        cnt = x
res += [cnt]
#计算剩余树总数
ans = l+1-sum([x[1]-x[0]+1 for x in res])
print(ans)