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