mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline N, Q = map(int, input().split()) A = [0] * (N+1) ans = 0 for _ in range(Q): l, r = map(int, input().split()) for i in range(l, r+1): if A[i]: ans -= 1 else: ans += 1 A[i] ^= 1 print(ans) if __name__ == '__main__': main()