#include <bits/stdc++.h>
long long x, y, z, t, m;
using namespace std;
int a[100009];
int main() {
  memset(a, 0, sizeof(a));
  int n, r, i, ma;
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%d", &r);
    a[r] = a[r - 1] + 1;
  }
  ma = 0;
  for (i = 0; i <= n; i++) ma = max(ma, a[i]);
  cout << n - ma << endl;
  return 0;
}
