#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 1;
int ARRAY[MAX];
int T[MAX];
int M = 0;
void SOLVE(int A) {
  for (int i = 0; i < A; ++i) {
    ARRAY[T[i]] = ARRAY[T[i] - 1] + 1;
    M = max(M, ARRAY[T[i]]);
  }
}
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> T[i];
  SOLVE(N);
  cout << (int)(N - M) << endl;
  return 0;
}
