#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > v;
  int temp;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    v.push_back(make_pair(temp, i));
  }
  sort(v.begin(), v.end());
  int ct = 1;
  int maxi = 1;
  for (int i = 1; i < v.size(); i++) {
    if (v[i].second > v[i - 1].second)
      ct++;
    else {
      if (ct > maxi) maxi = ct;
      ct = 1;
    }
  }
  maxi = max(maxi, ct);
  cout << n - maxi << endl;
  return 0;
}
