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