#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int temp;
  int a[n + 1];
  int ans[n + 1];
  for (int i = 1; i <= n; i++) ans[i] = 0;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    temp = a[i];
    if (temp == 1) {
      ans[temp] = 1;
      continue;
    }
    ans[temp] = ans[temp - 1] + 1;
  }
  int maxi = INT_MIN;
  for (int i = 1; i <= n; i++) {
    if (maxi < ans[i]) maxi = ans[i];
  }
  cout << n - maxi << endl;
}
