#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return (a % b == 0 ? b : gcd(b, a % b));
}
template <typename P>
struct Cmp {
  bool operator()(const P &p1, const P &p2) {
    if (p1.first > p2.first) return true;
    if (p1.first == p2.first) return p1.second < p2.second;
    return false;
  }
};
int main() {
  int n;
  cin >> n;
  int a[n], b[n + 1];
  for (int i = int(0); i < int(n); i++) {
    scanf("%d", &a[i]);
    b[i] = 0;
  }
  b[n] = 0;
  int ma = 0;
  for (int i = int(0); i < int(n); i++) {
    b[a[i]] = b[a[i] - 1] + 1;
    if (b[a[i]] > ma) ma = b[a[i]];
  }
  cout << n - ma << endl;
  return 0;
}
