#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> cnt(N + 1);
  for(int i = 0; i < N; i++) {
    int p;
    cin >> p;
    cnt[p] = cnt[p - 1] + 1;
  }
  cout << N - *max_element(cnt.begin(), cnt.end()) << endl;
  return 0;
}