N, Q = map(int, input().split()) LR = [list(map(int, input().split())) for _ in range(Q)] dp = [0 for _ in range(N)] cnt = 0 for l, r in LR: l-=1 r-=1 for i in range(l, r+1): cnt-=dp[i] dp[i]=1-dp[i] cnt+=dp[i] print(cnt)