#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define mp make_pair #define pb push_back #define all(x) (x).begin(),(x).end() #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector vb; typedef vector vi; typedef vector vvb; typedef vector vvi; typedef pair pii; const int INF=1e9; const double EPS=1e-9; const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1}; int LIS(vector &A) { int N = A.size(); vector dp(A.size() + 1, 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 (int i = 0; i < N; i++) { int a; cin >> a; if (a - i > 0) { A.push_back(a); } } cout << N - LIS(A) << endl; return 0; }