def main(): n,q = map(int,input().split()) lump = [0]*n ans = 0 for i in range(q): l,r = map(int,input().split()) l,r = l-1,r-1 for j in range(l,r+1): if lump[j] == 0: lump[j] = 1 ans += 1 else: lump[j] = 0 ans -= 1 print(ans) if __name__ == '__main__': main()