compress = lambda arr: {e: i for i, e in enumerate(sorted(set(arr)))} n, m = map(int, input().split()) t = (n - 1) * 2 a = [0] * m b = [0] * m for i in range(m): a[i], b[i] = map(int, input().split()) cp = compress([1] + a + b + [n]) n = len(cp) g = [[] for _ in range(n)] for i in range(m): g[cp[a[i]]].append(cp[b[i]]) dp = [0] * n for i in range(n - 1): dp[i + 1] = max(dp[i + 1], dp[i]) for j in g[i]: dp[j] = max(dp[j], dp[i] + 1) print(t - dp[n - 1])