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