#include <bits/stdc++.h>
using namespace std;
int main() {
  long n;
  cin >> n;
  long len[n + 1];
  for (long i = 1; i < n + 1; i++) {
    len[i] = 0;
  }
  long c;
  for (long i = 0; i < n; i++) {
    cin >> c;
    if (c == 1) {
      len[1] = 1;
    } else {
      len[c] = 1 + len[c - 1];
    }
  }
  long ma = 0;
  for (long i = 1; i < n + 1; i++) {
    if (len[i] > ma) {
      ma = len[i];
    }
  }
  cout << n - ma;
}
