#include <bits/stdc++.h>
using namespace std;
long long lcis(long long a[], long long n) {
  unordered_map<long long, long long> make_pair;
  long long dp[n], lastIndex;
  memset(dp, 0, sizeof(dp));
  ;
  long long mx = INT_MIN;
  for (long long i = 0; i < n; i++) {
    if (make_pair.find(a[i] - 1) != make_pair.end())
      lastIndex = make_pair[a[i] - 1] - 1, dp[i] = 1 + dp[lastIndex];
    else
      dp[i] = 1;
    make_pair[a[i]] = i + 1;
    mx = max(mx, dp[i]);
  }
  return mx;
}
int main() {
  long long n;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i];
  long long li = lcis(arr, n);
  cout << n - li << endl;
}
