#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int cur = 1, cnt = 0;
  vector<int> dp(n + 1, 0);
  for (int i = 0; i < n; i++) dp[a[i]] = dp[a[i] - 1] + 1;
  for (int i = 1; i < n + 1; i++) cnt = max(cnt, dp[i]);
  cout << n - cnt;
  return 0;
}
