#include <bits/stdc++.h>
using namespace std;
int a[111111], dp[111111];
int main() {
  int n, i, j, mx = 0;
  cin >> n;
  for (i = 0; i < n; i++) scanf("%d", a + i);
  for (i = n - 1; i >= 0; i--) {
    dp[a[i]] = dp[a[i] + 1] + 1;
    mx = max(mx, dp[a[i]]);
  }
  cout << n - mx << endl;
  return 0;
}
