f=lambda:[*map(int,input().split())] N,Q=f() p=[0]*N for i in range(Q): L,R=f() for j in range(L-1,R): p[j]^=1 print(sum(p))