#include <bits/stdc++.h>
using namespace std;
int T[100005];
int P[100005];
int n, pre = 0, res, r;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    T[a] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (T[i] > pre)
      r++;
    else {
      res = max(res, r);
      r = 1;
    }
    pre = T[i];
  }
  res = max(res, r);
  printf("%d\n", n - res);
  return 0;
}
