#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int mx = 0;
  map<int, bool> used;
  map<int, int> data;
  for (int i = 0; i < n; ++i) {
    used[a[i]] = true;
    if (used[a[i] - 1]) {
      data[a[i] - 1]++;
    }
  }
  for (int i = 0; i < n; ++i) {
    data[a[i]] += data[a[i] - 1];
  }
  for (map<int, int>::const_iterator it = data.begin(); it != data.end();
       it++) {
    mx = max(mx, (*it).second);
  }
  cout << n - (mx + 1);
  return 0;
}
