#include <bits/stdc++.h>
using namespace std;
int N, a[100100], dp[100100];
int main() {
  cin >> N;
  int i;
  for (i = 1; i <= N; i++) cin >> a[i];
  for (i = N; i >= 1; i--) dp[a[i]] = 1 + dp[a[i] + 1];
  int res = N + 1;
  for (i = 0; i <= N; i++) res = min(res, i + (N - i - dp[i + 1]));
  cout << res << "\n";
  return 0;
}
