#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = int(1e9);
const int MAX = 100007;
int n, a[MAX], order[MAX], mx;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    order[a[i]] = order[a[i] - 1] + 1;
    mx = max(mx, order[a[i]]);
  }
  cout << n - mx;
  return 0;
}
