#include <bits/stdc++.h>
using namespace std;
int n, m, k, a, l[100001];
int main() {
  cin >> n;
  m = n;
  while (m--) cin >> k, l[k] = l[k - 1] + 1, a = max(a, l[k]);
  cout << n - a;
  return 0;
}
