N, Q = map(int, input().split()) LR = [list(map(int, input().split())) for _ in range(Q)] la = [0] * N for l, r in LR: la[l - 1] += 1 la[r - 1] -= 1 ans = [0] * (N + 1) for i in range(N): ans[i + 1] = la[i] + ans[i] print(sum(i % 2 == 1 for i in ans))