#include <bits/stdc++.h>
using namespace std;
int a[100005], id[100005], dp[100005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    id[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    dp[i] = 1;
    if (id[i] > id[i - 1]) dp[i] = dp[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;
}
