#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 100005;
const int MOD = 1e9 + 7;
int n, a[N], pos[N], len[N];
int main() {
  while (scanf("%d", &n) != EOF) {
    int ans = INF;
    memset(len, 0, sizeof(len));
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      pos[a[i]] = i;
    }
    for (int i = 0; i < n; i++) {
      if (pos[a[i] - 1] > i)
        len[a[i]] = 1;
      else
        len[a[i]] = len[a[i] - 1] + 1;
    }
    for (int i = 0; i < n; i++) {
      ans = min(ans, n - len[a[i]]);
    }
    cout << ans << endl;
  }
  return 0;
}
