#include <bits/stdc++.h>
using namespace std;
int n;
int a[int(1e5) + 10], b[int(1e5) + 10];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> b[i], a[b[i]] = i;
  int ans = 1, cnt = 1;
  for (int i = 2; i <= n; i++) {
    if (a[i] > a[i - 1])
      cnt++;
    else
      ans = max(ans, cnt), cnt = 1;
  }
  ans = max(ans, cnt);
  cout << n - ans << endl;
  return 0;
}
