#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int n, tmp, a[100001], m;
int main() {
  cin >> n;
  for (int i = (0); i <= (n - 1); i++) {
    cin >> tmp;
    a[tmp] = a[tmp - 1] + 1;
    m = max(m, a[tmp]);
  }
  cout << n - m << endl;
  return 0;
}
