#include <bits/stdc++.h>
using namespace std;
int arr[100100];
int main() {
  int n, i, x, ans;
  while (cin >> n) {
    ans = 0;
    memset(arr, 0, sizeof(arr));
    for (i = 0; i < n; i++) {
      scanf("%d", &x);
      arr[x] = arr[x - 1] + 1;
      ans = max(ans, arr[x]);
    }
    cout << n - ans << endl;
  }
}
