N, M = map(int, input().split()) P = [list(map(int, input().split())) for i in range(M)] P.sort(key = lambda x: x[1]) ans = N last0 = 0 for i in range(M): l, r = P[i] if l <= last0 <= r: continue else: last0 = r ans -= 1 print(ans)