#include <bits/stdc++.h>
using namespace std;
long n, a[1000000 + 1], f[1000000 + 1], kq;
void doc() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
}
void xl() {
  for (int i = 1; i <= n; i++) {
    f[a[i]] = f[a[i] - 1] + 1;
    kq = max(kq, f[a[i]]);
  }
  cout << n - kq;
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  doc();
  xl();
}
