N, M = map(int, input().split()) X = [] A = [] for _ in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 X.append((a, b)) A.append(a) A.append(b) SA = sorted(set(A)) IA = {a: i for i, a in enumerate(SA)} X = [(IA[a], IA[b]) for a, b in X] X.sort(key = lambda x: x[0]) Y = [0] * len(SA) for a, b in X: Y[b] = max(Y[b], Y[a] + 1) print((N - 1) * 2 - Y[-1])