#include <bits/stdc++.h>
using namespace std;
int const MN = 1e5 + 100;
int n, r = 1, t[MN], ans;
int main() {
  cin >> n;
  for (int i = 1, a; i <= n; i++) {
    cin >> a;
    t[a] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (i > 1 && t[i] > t[i - 1])
      r++;
    else
      r = 1;
    ans = max(ans, r);
  }
  cout << n - ans;
}
