N,Q = map(int,input().split()) switch = [0]*(N) for i in range(Q): L,R = map(int,input().split()) for j in range(L-1,R): if switch[j] == 0: switch[j] = 1 else: switch[j] = 0 print(switch.count(1))