N,M=map(int,input().split()) L=[list(map(lambda x:int(x)-1,input().split())) for _ in range(M)] L=sorted(L,key=lambda x:x[1]) LS=set() for l,r in L: LS.add(l) LS.add(r) LS=sorted(list(LS)) D={LS[i]:i for i in range(len(LS))} n=len(LS) class segtree(): n=1 size=1 log=2 d=[0] op=None e=10**15 def update(self,k): self.d[k]=self.op(self.d[2*k],self.d[2*k+1]) def __init__(self,V,OP,E): #初期値(配列),演算,単位元で初期化 self.n=len(V) self.op=OP self.e=E self.log=(self.n-1).bit_length() self.size=1<>i) def get(self,p): #1点取得 assert 0<=p and p>=1 r>>=1 return self.op(sml,smr) def all_prod(self): #全区間取得 return self.d[1] V=[1]*n def OP(x,y): return min(x,y) seg=segtree(V,OP,2) cnt=0 for i in range(M): l,r=D[L[i][0]],D[L[i][1]] if seg.prod(l,r+1)==0: pass else: seg.set(r,0) cnt+=1 print(N-cnt)