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