N,M = map(int,input().split()) import heapq heap = [] for _ in range(M): l,r = map(int,input().split()) heapq.heappush(heap,(r,l)) cnt = 0 cur = -1 while heap: r,l = heapq.heappop(heap) if l<=cur: continue cur = r cnt += 1 print(N-cnt)