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