#include <bits/stdc++.h>
using namespace std;
set<int> s;
map<int, int> m;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (m.count(a - 1) > 0) {
      int cnt = m[a - 1] + 1;
      m.erase(a - 1);
      m[a] = cnt;
    } else {
      m[a] = 1;
    }
  }
  int mx = -1;
  for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {
    mx = max(mx, it->second);
  }
  cout << n - mx << endl;
  return 0;
}
