#include <bits/stdc++.h>
int n, temp, ans;
int a[100001];
int max(int a, int b) { return a > b ? a : b; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &temp);
    a[temp] = a[temp - 1] + 1;
    ans = max(ans, a[temp]);
  }
  printf("%d", n - ans);
  return 0;
}
