N,M = map(int,input().split()) A = sorted([list(map(int,input().split())) for _ in range(M)],key=lambda x:x[1]) cnt = 1 cur = A[0][1] for i in range(1,M): a,b = A[i] if a>=cur: cur = b cnt += 1 print(2*(N-1)-cnt)