#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int n;
int a[N], F[N];
int main() {
  int i, mymax = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) F[a[i]] = F[a[i] - 1] + 1;
  for (i = 1; i <= n; i++) mymax = max(mymax, F[i]);
  cout << n - mymax;
  return 0;
}
