n,m = map(int,input().split()) L = [] for i in range(m): l,r = map(int,input().split()) L.append([r,l]) L.sort() ans = n r = 0 if m != 1: while L[r+1][1] <= L[0][0]: r += 1 if r == m-1: break ans -= 1 for i in range(1,m): if i <= r: continue if r != m-1: while L[r+1][1] <= L[i][0]: r += 1 if r == m-1: break ans -= 1 else: ans = n-1 print(ans)