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