from collections import defaultdict import sys readline=sys.stdin.readline write=sys.stdout.write N,Q=map(int,readline().split()) lamp=[0]*N ans=0 for q in range(Q): l,r=map(int,readline().split()) l-=1 for i in range(l,r): if lamp[i]: ans-=1 else: ans+=1 lamp[i]^=1 print(ans)