#include <bits/stdc++.h>
using namespace std;
const int imod = 1e9 + 7;
const long long lmod = 1e18 + 7;
const int iinf = INT_MAX;
const long long linf = LLONG_MAX;
const double pi = 2 * acos(0.0);
const double eps = 1e-7;
int n;
int dp[(int)1e5 + 134];
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int p;
    cin >> p;
    dp[p] = dp[p - 1] + 1;
  }
  cout << n - *max_element(dp + 1, dp + n + 1);
  return 0;
}
