#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int idx[N + 1];
int dp[N + 1];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    idx[a[i]] = i;
  }
  int ans = 0, exp = 1, cnt = 0;
  for (int i = 0; i < n; i++) {
    if (idx[a[i] - 1] < i + 1)
      dp[a[i]] = dp[a[i] - 1] + 1;
    else
      dp[a[i]] = 1;
  }
  for (int i = n - 1; i >= 0; i--) {
    ans = max(ans, dp[a[i]]);
  }
  ans = n - ans;
  cout << ans;
  return 0;
}
