#include <bits/stdc++.h>
using namespace std;
int num[100005];
int loc[100005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
  }
  for (int i = 1; i <= n; i++) {
    loc[num[i]] = i;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int tmp = 1;
    while (loc[i] < loc[i + 1]) {
      tmp++;
      i++;
    }
    ans = max(ans, tmp);
  }
  cout << n - ans << endl;
  return 0;
}
