#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int bit[N];
int a[N];
void update(int u, int v) {
  while (u < N) {
    bit[u] = max(bit[u], v);
    u += (u & (-u));
  }
}
int get(int u) {
  int ans = 0;
  while (u > 0) {
    ans = max(ans, bit[u]);
    u -= (u & (-u));
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int ans = 0;
  for (int x = 0; x < n; ++x) {
    int t;
    cin >> t;
    a[t] = a[t - 1] + 1;
    ans = max(ans, a[t]);
  }
  cout << n - ans << endl;
}
