//================================= // Created on: 2018/07/07 18:00:43 //================================= #include #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using ld = long double; constexpr ll MOD = 1000000007LL; template constexpr T INF = numeric_limits::max() / 10; mt19937 mt{random_device{}()}; template int LongestIncreasingSubsequence(const vector& a) { const int n = a.size(); vector dp(n, INF); for (int i = 0; i < n; i++) { *upper_bound(dp.begin(), dp.end(), a[i]) = a[i]; } return lower_bound(dp.begin(), dp.end(), INF) - dp.begin(); } int main() { int N; cin >> N; vector A; for (ll i = 0, a; i < N; i++) { cin >> a; if (a > i) { A.push_back(a - i); } } const int L = LongestIncreasingSubsequence(A); cout << N - L << endl; return 0; }