#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  ll n, i, j, t, x;
  vector<ll> bi(100005);
  cin >> t;
  j = t;
  ll p = 0;
  while (t--) {
    cin >> x;
    bi[x] = bi[x - 1] + 1;
    p = max(p, bi[x]);
  }
  cout << j - p << endl;
}
