#include <bits/stdc++.h>
using namespace std;
long long suma[100005];
long long gcd(long long a, long long b) {
  if (a > b) swap(a, b);
  long long c;
  while (a != 0) {
    c = a;
    a = b % a;
    b = c;
  }
  return b;
}
int dp[100005];
int ar[100005];
bool vis[100005];
int p[100005];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%d", &ar[1]);
  vis[ar[1]] = 1;
  p[ar[1]] = 1;
  dp[0] = 0;
  dp[1] = 1;
  int a = 1;
  int i;
  for (i = 2; i <= n; i++) {
    scanf("%d", &ar[i]);
    vis[ar[i]] = 1;
    p[ar[i]] = i;
    if (vis[ar[i] - 1] == 1)
      dp[i] = dp[p[ar[i] - 1]] + 1;
    else
      dp[i] = 1;
    a = max(dp[i], a);
  }
  cout << n - a;
}
