#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  vector<int> f(n + 1, 0);
  for (int& x : p) {
    f[x] = f[x - 1] + 1;
  }
  cout << n - *max_element(f.begin(), f.end());
}
