#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int dp[n + 1];
  memset(dp, 0, sizeof dp);
  int ans = 1;
  for (int i = 0; i < n; i++) {
    dp[a[i]] = dp[a[i] - 1] + 1;
    ans = max(ans, dp[a[i]]);
  }
  cout << n - ans;
}
