#include <bits/stdc++.h>
using namespace std;
int p[11111111], ans, q[11111111], b[11111111], d[100001], mx, a[11111111];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    d[a[i]] = d[a[i] - 1] + 1;
    mx = max(mx, d[a[i]]);
  }
  cout << n - mx;
}
