#include <bits/stdc++.h>
using namespace std;
int arra[1000007];
int main() {
  int n, x, maxii = 0;
  cin >> n;
  int i = 0;
  for (i = 0; i < n; i++) {
    cin >> x;
    arra[x] = arra[x - 1] + 1;
    if (arra[x] > maxii) maxii = arra[x];
  }
  cout << n - maxii;
  return 0;
}
