#include <bits/stdc++.h>
int jl[100005];
int main() {
  int n, ans, k;
  while (~scanf("%d", &n)) {
    ans = 0;
    memset(jl, 0, sizeof jl);
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &k);
      if (jl[k - 1]) {
        jl[k] = jl[k - 1] + 1;
      } else
        jl[k] = 1;
      ans = ans < jl[k] ? jl[k] : ans;
    }
    printf("%d\n", n - ans);
  }
  return 0;
}
