N,M = map(int,input().split()) lsLR = [] for i in range(M): L,R = map(int,input().split()) lsLR.append((L,R)) lsLR.sort(reverse=True) cnt = 0 ind = 0 while lsLR: l,r = lsLR.pop() rr = r cnt += 1 while lsLR: l,r = lsLR[-1] if l <= rr: lsLR.pop() continue else: break print(N-cnt)