#include <bits/stdc++.h>
using namespace std;
int findLIS(int A[], int n) {
  unordered_map<int, int> hash;
  int LIS_size = 1;
  int LIS_index = 0;
  hash[A[0]] = 1;
  for (int i = 1; i < n; i++) {
    hash[A[i]] = hash[A[i] - 1] + 1;
    if (LIS_size < hash[A[i]]) {
      LIS_size = hash[A[i]];
      LIS_index = A[i];
    }
  }
  return LIS_size;
}
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int ans = findLIS(a, n);
  cout << n - ans << endl;
  return 0;
}
