L,M=map(int,input().split())
Tree=[1]*(L+1)#长度为L,1为种满了树
cun=0
for i in range(M):
    l,r=map(int,input().split())
    for j in range(l,r+1):
        Tree[j]=0
for i in range(len(Tree)):
    if Tree[i]==1:
        cun+=1
print(cun)