#include using i64 = long long; using l64 = long double; template struct Fenwick { int n; std::vector a; Fenwick(int n_ = 0) { init(n_); } void init(int n_) { n = n_; a.assign(n + 5, T{}); } void add(int x, const T &v) { for (int i = x; i <= n; i += i & -i) { a[i] = a[i] + v; } } T sum(int x) { T ans{}; for (int i = x; i > 0; i -= i & -i) { ans = ans + a[i]; } return ans; } T rangeSum(int l, int r) { return sum(r) - sum(l); } int select(const T &k) { int x = 0; T cur{}; for (int i = 1 << std::__lg(n); i; i /= 2) { if (x + i <= n && cur + a[x + i] <= k) { x += i; cur = cur + a[x]; } } return x; } }; struct Max { int a = 0; Max operator+(Max x) const { return {std::max(a, x.a)}; } }; void DAOQI() { int n; std::cin >> n; std::vector a(n + 1); std::set se; for (int i = 1; i <= n; i++) { std::cin >> a[i]; if (a[i] >= i) { se.insert(a[i] - i); } } std::vector d(se.begin(), se.end()); std::map mp; for (int i = 0; i < d.size(); i++) { mp[d[i]] = i + 1; } int res = 0; Fenwick fw(d.size()); for (int i = 1; i <= n; i++) { int x = a[i] - i; if (!se.count(x)) continue; int q = fw.sum(mp[x]).a; res = std::max(res, q + 1); fw.add(mp[x], {q + 1}); } std::cout << n - res << "\n"; } signed main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int T = 1; //std::cin >> T; while (T--) DAOQI(); return 0; }