#include <bits/stdc++.h>
using namespace std;
int cnt[100001];
int main() {
  int n, k;
  cin >> n;
  int ans = 1;
  int m = n;
  while (n--) {
    cin >> k;
    cnt[k] = cnt[k - 1] + 1;
    ans = max(ans, cnt[k]);
  }
  cout << m - ans;
}
