#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int p = 2008;
const double eps = 1e-8;
int a[N], f[N];
int ans, m;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= n; i++) {
    f[a[i]] = f[a[i] - 1] + 1;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, f[i]);
  }
  cout << n - ans << endl;
  return 0;
}
