#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int dp[n + 1];
  memset(dp, 0, sizeof(dp));
  int right = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    dp[a] = dp[a - 1] + 1;
    if (dp[a] > dp[right]) right = a;
  }
  int cur = right;
  while (dp[cur] > 1) --cur;
  int left = cur;
  cout << n - dp[right] << endl;
  return 0;
}
