#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; ++i) cin >> v[i];
  map<int, int> mapa;
  for (int i = 0; i < N; ++i) {
    if (mapa.find(v[i] - 1) != mapa.end()) {
      mapa[v[i]] = mapa[v[i] - 1] + 1;
    } else {
      mapa[v[i]] = 1;
    }
  }
  int maximo = 0;
  for (map<int, int>::iterator i = mapa.begin(); i != mapa.end(); ++i) {
    maximo = max(maximo, i->second);
  }
  cout << N - maximo << endl;
  return 0;
}
