#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int m[100100] = {0};
  int a = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    m[t] = m[t - 1] + 1;
    a = max(a, m[t]);
  }
  cout << n - a;
}
