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