#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< >(b,vector(c,d)) #define vvv(a,b,c,d,e) vector > >(b,vv(a,c,d,e)) using ll = long long; using pii = pair; using vi = vector; using vll = vector; int longestIncreasingSubsequence(const vector &a) { vector L(a.size(), LLONG_MAX/2); L[0] = a[0]; int t = 0; // legnth-1 for (int i = 1; i < (int)a.size(); ++i) if(a[i]>0){ // 広義(<=), 狭義(<) if (L[t] <= a[i])L[++t] = a[i]; else { auto it = lower_bound(L.begin(), L.begin() + t, a[i] + 1); if (it != L.end()) *it = a[i]; } } return t + 1; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int N; cin >> N; vll a(N); rep(i, N) { cin >> a[i]; a[i] -= i; } cout << N-longestIncreasingSubsequence(a) << endl; }