#include <bits/stdc++.h>
using namespace std;
int f[100050];
int main() {
  int n;
  int ans = 1;
  int x = 0;
  while (~scanf("%d", &n)) {
    memset(f, 0, sizeof(f));
    for (int i = 0; i < n; i++) {
      scanf("%d", &x);
      f[x] = f[x - 1] + 1;
      ans = max(ans, f[x]);
    }
    printf("%d\n", n - ans);
  }
  return 0;
}
