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] Z = [[] for _ in range(len(SA))] for a, b in X: Z[a].append(b) Y = [0] * len(SA) for i in range(len(SA)): Y[i] = max(Y[i], Y[i-1]) for j in Z[i]: Y[j] = max(Y[j], Y[i] + 1) print((N - 1) * 2 - Y[-1])