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