#include <bits/stdc++.h>
using namespace std;
int a[150000];
int dp[150000];
int main() {
  int n;
  while (cin >> n) {
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      dp[i] = 0;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      dp[a[i]] = dp[a[i] - 1] + 1;
    }
    for (int i = 1; i <= n; i++) {
      if (ans < dp[i]) ans = dp[i];
    }
    cout << n - ans << endl;
  }
}
