#include <bits/stdc++.h>
using namespace std;
int T[300000];
int N;
int main() {
  iostream::sync_with_stdio(false);
  cin.tie();
  cin >> N;
  int t;
  for (int i = 0; i < N; i++) {
    cin >> t;
    T[t] = T[t - 1] + 1;
  }
  int m = 0;
  for (int i = 1; i <= N; i++) m = max(m, T[i]);
  cout << N - m;
}
