#include <bits/stdc++.h>
using namespace std;
int a[100010], ar[100010];
int main() {
  int n, track = -100002, i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    ar[a[i]] = ar[a[i] - 1] + 1;
    track = max(ar[a[i]], track);
  }
  cout << n - track << endl;
}
