#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int vis[N];
int ans[N];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    vis[a] = 1;
    ans[a] = 1;
    if (vis[a - 1]) ans[a] += ans[a - 1];
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    res = max(res, ans[i]);
  }
  cout << n - res << endl;
  return 0;
}
