#include <bits/stdc++.h>
using namespace std;
vector<int> d;
int main() {
  int n, pos[100069] = {}, ans[100069] = {}, maxi = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    ans[x] = ans[x - 1] + 1;
    maxi = max(maxi, ans[x]);
  }
  cout << n - maxi << endl;
  return 0;
}
