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