N,Q = map(int,input().split()) lamp = [0] * N for i in range(Q): Li,Ri = map(int,input().split()) for j in range(Li,Ri+1): if lamp[j-1] == 0: lamp[j-1] = 1 else: lamp[j-1] = 0 print(len([1 for k in lamp if k == 1]))