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