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