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