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