N,M = map(int,input().split()) R = [[]]*M for i in range(M): l,r = map(int,input().split()) R[i] = [r+1,l] R.sort() ans=0 con_l=0 for i in range(M): if con_l <= R[i][1]: ans += 1 con_l = R[i][0] print(N-ans)