#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 10;
int a[M];
int b[M];
int main() {
  int n;
  scanf("%d", &n);
  int ans = 1;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    b[a[i]] = b[a[i] - 1] + 1;
    ans = max(ans, b[a[i]]);
  }
  printf("%d\n", n - ans);
  return 0;
}
