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

int main() {
    int n;
    cin >> n;
    int max_len = 0;
    vector<int> l(n + 1);
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        l[p] = l[p - 1] + 1;
        max_len = max(max_len, l[p]);
    }

    cout << n - max_len << endl;
}