#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n; cin >> n;
    vector<int> p(n);
    for (int &pi: p) cin >> pi;
    vector<int> dp(n + 1);
    for (int cur: p) dp[cur] = dp[cur - 1] + 1;
    int res = n - *max_element(dp.begin(), dp.end());
    cout << res << endl;
    return 0;
}