L,M=map(int,input().split()) m=[1 for x in range(L+1)] for j in range(M): a,b=map(int,input().split()) for i in range(a,b+1): m[i]=0 print(sum(m))