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 ams = sum(i % 2 == 1 for i in la) print(ans)