#include <bits/stdc++.h>
using namespace std;
int v[100001];
int main() {
  int n, l, c, ctr = 0, i, x;
  cin >> n;
  for (i = 0; i <= n - 1; i++) {
    cin >> x;
    v[x] = 1 + v[x - 1];
    ctr = max(ctr, v[x]);
  }
  cout << n - ctr;
  return 0;
}
