#include <bits/stdc++.h>
using namespace std;
const long long int N = 200005;
bool bm[501][501];
int main() {
  ios::sync_with_stdio(false);
  long long int n;
  cin >> n;
  long long int a[n + 1], pos[n + 1];
  for (long long int i = 1; i < n + 1; i++) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  pos[0] = 0;
  long long int lon = 1;
  long long int cnt = 0;
  for (long long int i = 1; i < n + 1; i++) {
    if (pos[i] > pos[i - 1]) {
      cnt++;
    } else {
      cnt = 1;
    }
    lon = max(lon, cnt);
  }
  cout << n - lon << endl;
  return 0;
}
