#include <bits/stdc++.h>
using namespace std;
const int N = 2000005;
int a[N], ans, x, n;
int main() {
  scanf("%d", &n);
  memset(a, 0, sizeof(a));
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    a[x] = a[x - 1] + 1;
    if (a[x] > ans) ans = a[x];
  }
  printf("%d\n", n - ans);
}
