from itertools import accumulate N,Q=map(int,input().split()) lamp=[0]*(N) cnt=0 for _ in range(Q): l,r=map(int,input().split()) for i in range(l-1,r): if lamp[i]: cnt-=1 else: cnt+=1 lamp[i]=1-lamp[i] print(cnt)