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