#include <bits/stdc++.h>
using namespace std;
int n;
int t[100001];
int d[100001];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> t[i];
  int maxi = 0;
  for (int i = 1; i <= n; i++) {
    d[t[i]] = 1 + d[t[i] - 1];
    maxi = max(maxi, d[t[i]]);
  }
  cout << n - maxi << endl;
  return 0;
}
