#include <bits/stdc++.h>
const int INF = 1 << 30;
inline int read() {
  int x = 0;
  bool f = false;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  if (f) return -x;
  return x;
}
const int MAXN = 100000, D = 50;
int n, ans = 0;
int a[MAXN + D], at[MAXN + D];
int f[MAXN + D];
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read(), at[a[i]] = i;
  for (int i = 1; i <= n; i++) {
    if (at[a[i] - 1] < i)
      f[i] = f[at[a[i] - 1]] + 1;
    else
      f[i] = 1;
    if (f[i] > ans) ans = f[i];
  }
  printf("%d", n - ans);
  return 0;
}
