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