N,M = map(int,input().split()) LR = [list(map(int,input().split())) for _ in range(M)] LR.sort() LR.append([10**9+1,10**9+2]) cnt = 0 lc = 0 rmin = 10**10 for l,r in LR: if lc < l: lc = l rmin = min(r,rmin) if l > rmin: cnt += 1 rmin = r print(N-cnt)