#include <bits/stdc++.h>
using namespace std;
int a[1000005];
int main() {
  int n, i, ma = 0, x;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    a[x] = a[x - 1] + 1;
    ma = max(a[x], ma);
  }
  cout << n - ma << endl;
  return 0;
}
