#include <bits/stdc++.h>
using namespace std;
int counts[100100];
int main() {
  int n;
  cin >> n;
  int temp;
  memset(counts, 0, sizeof(counts));
  int maxx = -1;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    counts[temp] = counts[temp - 1] + 1;
    maxx = max(counts[temp], maxx);
  }
  cout << n - maxx << endl;
  return 0;
}
