#include <bits/stdc++.h>
using namespace std;
int n;
int inp[100005];
int has[100005];
int cal[100005];
int fnc(int x) {
  if (cal[x]) return cal[x];
  int ret = 1;
  if (has[x] > has[x + 1]) return cal[x] = ret;
  ret += fnc(x + 1);
  cal[x] = ret;
  return cal[x];
}
int main() {
  int i, j;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    scanf("%d", &inp[i]);
    has[inp[i]] = i + 1;
  }
  int maxx = 0;
  for (i = 1; i < n + 1; ++i) {
    maxx = max(maxx, fnc(i));
  }
  cout << n - maxx << endl;
}
