#include <bits/stdc++.h>
using namespace std;
int a[100010], pos[100010];
int main() {
  register int n;
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i) scanf("%d", &a[i]), pos[a[i]] = i;
  register int ans = 0, tmp = 0;
  for (register int i = 1; i <= n; ++i)
    if (pos[i] > pos[i - 1])
      ++tmp;
    else
      (ans < (tmp) ? ans = (tmp) : 0), tmp = 1;
  (ans < (tmp) ? ans = (tmp) : 0);
  printf("%d\n", n - ans);
  return 0;
}
