#include <bits/stdc++.h>
using namespace std;
int n, a[100005], mx, b;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b;
    a[b] = a[b - 1] + 1;
    mx = max(a[b], mx);
  }
  cout << n - mx;
  return 0;
}
