import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) U = 10 ** 5 N, Q = map(int, input().split()) ans = 0 lamp = [0] * (N + 1) for _ in range(Q): L, R = map(int, input().split()) for i in range(L, R+1): lamp[i] ^= 1 if lamp[i]: ans += 1 else: ans -= 1 print(ans)