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