#include <bits/stdc++.h>
const long MAXN = 100000;
using namespace std;
long dp[MAXN + 5];
long max(long a, long b) {
  if (a > b)
    return a;
  else
    return b;
}
int main() {
  long i, j, n, a[MAXN + 5], m, k;
  bool ok;
  scanf("%ld", &n);
  m = 0;
  for (i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
    dp[a[i]] = dp[a[i] - 1] + 1;
    m = max(m, dp[a[i]]);
  }
  printf("%ld\n", n - m);
  return 0;
}
