#yukicoder No.1673 Lamps on a line N, Q = map(int, input().split()) lamp = [0] * N ans = 0 for _ in range(Q): L, R = map(int, input().split()) for i in range(L - 1, R): if lamp[i] == 0: lamp[i] = 1 ans += 1 else: lamp[i] = 0 ans -= 1 print(ans)