#include <bits/stdc++.h>
using namespace std;
const int mxvl = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> vc(n + 5);
  for (auto i = 0; i < n; i++) {
    long long x;
    cin >> x;
    vc[x] = vc[x - 1] + 1;
  }
  cout << n - *max_element(vc.begin(), vc.end()) << "\n";
}
