n,q=map(int,input().split()) ans=0 d=[0]*(n+1) for i in range(q): l,r=map(int,input().split()) for j in range(l,r+1): if d[j]==0: d[j]=1 ans+=1 else: d[j]=0 ans-=1 print(ans)