#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, N = 100010;
const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
int n, a[N], f[N], b[N], ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    int x = a[i];
    if (b[x - 1] < i)
      f[i] = f[b[x - 1]] + 1;
    else
      f[i] = 1;
  }
  for (int i = 1; i <= n; i++) ans = max(ans, f[i]);
  cout << n - ans << "\n";
}
