#include <bits/stdc++.h>
using namespace std;
int n, pos[200001], c, r;
inline void init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &r);
    pos[r] = pos[r - 1] + 1;
    c = max(c, pos[r]);
  }
  cout << n - c;
}
int main() {
  init();
  return 0;
}
