#include <bits/stdc++.h>
using namespace std;
int A[100001];
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int n, i, j, k, x, y, z;
  cin >> n;
  z = 0;
  for (i = 1; i <= n; ++i) {
    cin >> x;
    A[x] = A[x - 1] + 1;
    z = max(z, A[x]);
  }
  cout << n - z << endl;
  return 0;
}
