#include <bits/stdc++.h>
using namespace std;
int num[100005];
int n;
void solve() {
  int val;
  for (int i = 0; i < n; i++) num[i] = 0;
  for (int i = 0; i < n; i++) {
    cin >> val;
    val -= 1;
    if (val == 0 || num[val - 1] == 0)
      num[val] = 1;
    else
      num[val] = num[val - 1] + 1;
  }
  val = 0;
  for (int i = 0; i < n; i++)
    if (num[i] > val) val = num[i];
  cout << n - val << endl;
}
int main() {
  while (cin >> n) {
    solve();
  }
}
