N,Q = map(int,input().split()) lr = [list(map(int,input().split()))for _ in range(Q)] s = [0]*(N+1) ans = 0 for l,r in lr: tmp1 = sum(s[l-1:r]) for i in range(l-1,r): s[i]+=1 s[i]%=2 tmp2 = sum(s[l-1:r]) ans+=(tmp2-tmp1) print(ans)