def main(): import sys input = sys.stdin.buffer.readline n, q = map(int, input().split()) lis = [0] * n s = 0 for _ in range(q): l, r = map(int, input().split()) for i in range(l - 1, r): lis[i] ^= 1 if lis[i]: s += 1 else: s -= 1 print(s) if __name__ == '__main__': main()