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