#include <bits/stdc++.h>
int n, len;
int a[100005];
int f[100005];
using namespace std;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    f[a[i]] = f[a[i] - 1] + 1;
    len = max(len, f[a[i]]);
  }
  printf("%d", n - len);
  return 0;
}
