#include <bits/stdc++.h>
using namespace std;
int n, arr[123456], dp[123456];
int main() {
  memset(dp, 0, sizeof dp);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  for (int i = n - 1; i >= 0; i--) {
    dp[arr[i]]++;
    dp[arr[i]] += dp[arr[i] + 1];
  }
  int sol = 0;
  for (int i = 0; i <= n; i++) {
    sol = max(sol, dp[i]);
  }
  printf("%d\n", n - sol);
  return 0;
}
