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