#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int arr[n + 5];
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  int mx = 1;
  int pos[n + 5];
  for (int i = 0; i < n + 5; i++) pos[i] = 0;
  for (int i = 0; i < n; i++) {
    if (pos[arr[i] - 1]) {
      pos[arr[i]] = pos[arr[i] - 1] + 1;
    } else
      pos[arr[i]] = 1;
    if (mx < pos[arr[i]]) mx = pos[arr[i]];
  }
  cout << n - mx << endl;
}
