#include <bits/stdc++.h>
using namespace std;
int a[120001], p[120001], nxt[120001], dp[120001], n, i, ans;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = n; i >= 1; i--) {
    if (p[a[i] + 1] != 0) nxt[i] = p[a[i] + 1];
    p[a[i]] = i;
  }
  for (i = 1; i <= n; i++) dp[i] = 1;
  for (i = 1; i <= n; i++)
    if (nxt[i] != 0) dp[nxt[i]] = max(dp[nxt[i]], dp[i] + 1);
  for (i = 1; i <= n; i++) ans = max(ans, dp[i]);
  cout << n - ans << '\n';
  return 0;
}
