#include <bits/stdc++.h>
using namespace std;
void fre() {
  freopen("c://test//input.in", "r", stdin);
  freopen("c://test//output.out", "w", stdout);
}
template <class T1, class T2>
inline void gmax(T1 &a, T2 b) {
  if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1 &a, T2 b) {
  if (b < a) a = b;
}
const int N = 1e5 + 10, M = 0, Z = 1e9 + 7, ms63 = 1061109567;
int n, x;
int e[N];
int main() {
  while (~scanf("%d", &n)) {
    memset(e, 0, sizeof(e));
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &x);
      e[x] = e[x - 1] + 1;
      gmax(ans, e[x]);
    }
    printf("%d\n", n - ans);
  }
  return 0;
}
