#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int* arr = new int[n];
  int* found = new int[n + 1];
  for (int i = 1; i <= n; i++) found[i] = 0;
  int maxval = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 1)
      found[arr[i]] = 1;
    else
      found[arr[i]] = (found[(arr[i] - 1)] + 1);
    maxval = max(maxval, found[arr[i]]);
  }
  cout << n - maxval << endl;
}
