#include <bits/stdc++.h>
using namespace std;
int arr[100005];
int main() {
  int num1, temp, maxi = 0;
  cin >> num1;
  for (int A = 1; A <= num1; A++) {
    cin >> temp;
    arr[temp] = arr[temp - 1] + 1;
    maxi = max(maxi, arr[temp]);
  }
  cout << num1 - maxi << endl;
}
