n, q = map(int, input().split()) lamp = [0] * n cnt = 0 for i in range(q): l, r = map(int, input().split()) for j in range(l-1, r): if lamp[j] == 0: lamp[j] = 1 cnt += 1 else: lamp[j] = 0 cnt -= 1 print(cnt)