#include <bits/stdc++.h>
using namespace std;
int max1(int a, int b) {
  if (a > b) return a;
  return b;
}
int num[100003], dp[100003], c[100003];
int main() {
  int max = 0, i, j, n;
  cin >> n;
  for (i = 1; i <= n; i++) scanf("%d", &num[i]);
  for (i = 1; i <= n; i++) dp[num[i]] = max1(1, dp[num[i] - 1] + 1);
  for (i = 1; i <= n; i++) max = max1(max, dp[num[i]]);
  cout << n - max << endl;
  return 0;
}
