N,Q = map(int,input().split()) ls = [0]*N cnt = 0 for i in range(Q): L,R = map(int,input().split()) L -= 1 bf = 0 for j in range(L,R): bf += ls[j] af = 0 for j in range(L,R): ls[j]^=1 af += ls[j] cnt += af-bf print(cnt)