#include <bits/stdc++.h>
using namespace std;
int n;
int a[111111], b[111111], f[111111];
int x, m1 = 0, m2 = 0;
int ans;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    f[x] = f[x - 1] + 1;
    ans = max(f[x], ans);
  }
  cout << n - ans;
}
