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