#include <bits/stdc++.h>
using namespace std;
const long long N = 2 * 1e6 + 10;
const long long INF = 2e9;
const long long inf = -1e18;
const long long MOD = 1e9 + 7;
const long long base = 1000 * 1000 * 1000;
long long x, b[N], n, ans;
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    b[x] = b[x - 1] + 1;
    ans = max(ans, b[x]);
  }
  cout << n - ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long t = 1;
  while (t--) {
    solve();
  }
}
