#include <bits/stdc++.h>
using namespace std;
int n, s[100005];
int main() {
  scanf("%d", &n);
  memset(s, 0, sizeof(s));
  for (int i = (1); i <= (n); i++) {
    int x;
    scanf("%d", &x);
    s[x] = s[x - 1] + 1;
  }
  int ans = 0;
  for (int i = (1); i <= (n); i++) ans = max(ans, s[i]);
  printf("%d\n", n - ans);
  return 0;
}
