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