from sys import stdin n, q, *indata = map(int, stdin.read().split()) ans = 0 onoff = [0 for i in range(n+1)] offset = 0 for i in range(q): l, r = indata[offset + 2*i],indata[offset + 2*i+1] for i in range(l,r+1): if onoff[i] == 0: onoff[i] = 1 ans += 1 else: onoff[i] = 0 ans -= 1 print("{}".format(ans))