#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int train[N];
int dp[N];
int vit[N];
int main() {
  int n;
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      cin >> train[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      dp[train[i]] = dp[train[i] - 1] + 1;
      ans = max(ans, dp[train[i]]);
    }
    cout << n - ans << endl;
  }
  return 0;
}
