import sys input = sys.stdin.readline N,M=map(int,input().split()) EX=[list(map(int,input().split())) for i in range(M)] LIST=[] for x,y in EX: LIST.append(x) LIST.append(y) LIST=sorted(set(LIST)) D={LIST[i]:i for i in range(len(LIST))} E=[[] for i in range(len(LIST))] for x,y in EX: E[D[x]].append(D[y]) def seg_function(x,y): # Segment treeで扱うfunction return max(x,y) seg_el=1<<(len(LIST).bit_length()) # Segment treeの台の要素数 SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化 def update(n,x,seg_el): # A[n]をxへ更新 i=n+seg_el SEG[i]=x i>>=1 # 子ノードへ while i!=0: SEG[i]=seg_function(SEG[i*2],SEG[i*2+1]) i>>=1 def getvalues(l,r): # 区間[l,r)に関するseg_functionを調べる L=l+seg_el R=r+seg_el ANS=0 while L>=1 R>>=1 return ANS for i in range(len(LIST)): k=getvalues(0,i+1) for to in E[i]: update(to,k+1,seg_el) ANS=SEG[1] print(N*2-2-ANS)