N,M = map(int,input().split()) dat = [0] * M for _ in range(M): l,r = map(int,input().split()) dat[_] = (r,l) dat.sort(reverse = True) count = 0 now = 0 while len(dat): r,l = dat.pop() if l > now: count += 1 now = r print(N - count)