#include <bits/stdc++.h>
using namespace std;
int a[100010], dp[100010], rec[100010];
int n;
int main() {
  while (~scanf("%d", &n)) {
    int maxn = 0;
    for (int i = 1; i <= n; i++) {
      dp[i] = 1;
      scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n; i++) {
      rec[a[i]] = 1;
      if (rec[a[i] - 1] > 0) {
        dp[a[i]] = dp[a[i] - 1] + 1;
      }
      maxn = max(maxn, dp[a[i]]);
    }
    printf("%d\n", n - maxn);
  }
}
