#include <bits/stdc++.h>
using namespace std;
bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); }
void solve() {
  long long int n;
  cin >> n;
  map<long long int, long long int> hash;
  long long int ans = 0;
  for (long long int i = 0; i < n; ++i) {
    long long int x;
    cin >> x;
    hash[x] = hash[x - 1] + 1;
    ans = max(ans, hash[x]);
  }
  cout << n - ans;
}
int32_t main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  while (T--) solve();
  return 0;
}
