#include <bits/stdc++.h>
using namespace std;
int arr[1000005];
int n;
int main() {
  int ans = 0;
  cin >> n;
  int i;
  for (i = 0; i < n; i++) {
    int x;
    cin >> x;
    arr[x] = 1 + arr[x - 1];
    ans = max(ans, arr[x]);
  }
  cout << n - ans << endl;
}
