#include <bits/stdc++.h>
using namespace std;
int kol[100007] = {0};
int main() {
  int n;
  cin >> n;
  int m1 = 1;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    if (kol[a - 1] > 0)
      kol[a] = kol[a - 1] + 1;
    else
      kol[a] = 1;
    m1 = max(m1, kol[a]);
  }
  cout << (n - m1);
  return 0;
}
