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