#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t;
  scanf("%d", &n);
  int *niz = new int[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &t);
    niz[i] = t;
  }
  int *d = new int[n + 1];
  for (int i = 0; i <= n; i++) {
    d[i] = 0;
  }
  int maks = 1;
  for (int i = 0; i < n; i++) {
    if (niz[i] == 1) {
      d[niz[i]] = 1;
      continue;
    }
    d[niz[i]] = d[niz[i] - 1] + 1;
    maks = max(maks, d[niz[i]]);
  }
  maks = n - maks;
  printf("%d", maks);
}
