#include <bits/stdc++.h>
using namespace std;
const long long inf = (1LL << 60);
const int N = 1e5 + 7;
int n, m;
bool vis[N];
int main() {
  std ::ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  vector<int> vt(n), pos(n + 1);
  for (int i = 0; i < n; ++i) {
    cin >> vt[i];
    pos[vt[i]] = i + 1;
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      vis[i] = true;
      int st = i;
      int jump = 1;
      for (int j = i + 1; j <= n; ++j) {
        if (!vis[j] and pos[j] > pos[st]) {
          st = j;
          jump++;
          vis[st] = true;
        } else {
          break;
        }
      }
      ans = max(ans, jump);
    }
  }
  cout << n - ans << '\n';
  return 0;
}
