#include <bits/stdc++.h>
using namespace std;
const int INF = 1E9;
const int maxn = 1E5 + 10;
int p[maxn];
int ans[maxn];
int main() {
  int N;
  cin >> N;
  for (decltype(N) i = 0; i < N; i++) cin >> p[i];
  int res = 0;
  for (decltype(N) i = 0; i < N; i++) {
    ans[p[i]] = ans[p[i] - 1] + 1;
    res = max(res, ans[p[i]]);
  }
  cout << N - res << endl;
  return 0;
}
