n, q = map(int, input().split()) lis = [0] * n for _ in range(q): l, r = map(int, input().split()) for i in range(l - 1, r): lis[i] ^= 1 print(sum(lis))