#include <bits/stdc++.h>
int n, m, t[100009], i, maxs;
int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &m);
    t[m] = t[m - 1] + 1;
    if (maxs < t[m]) maxs = t[m];
  }
  printf("%d\n", n - maxs);
  return 0;
}
