#include <bits/stdc++.h>
using namespace std;
int A[100000 + 1];
int main() {
  int n;
  scanf("%d", &n);
  int ANS, len = 0, M = 0;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    if (A[v[i] - 1] > 0)
      A[v[i]] = A[v[i] - 1] + 1;
    else
      A[v[i]] = 1;
    M = max(M, A[v[i]]);
  }
  ANS = n - M;
  printf("%d", (ANS));
  return 0;
}
