#include<bits/stdc++.h>
using namespace std;

const int MAX_N = 2e5;
int dp[MAX_N+5];

int main(){
    int n; cin >> n;

    for(int i=0;i<n;i++){
        int p; cin >> p;
        dp[p] = dp[p-1] + 1;
    }

    cout << n - *max_element(dp+1, dp+n+1) << endl;
    return 0;
}
