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