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