#include <bits/stdc++.h>
using namespace std;
int p[1234567];
int n;
int s[1234567];
int main(void) {
  ios_base ::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> p[i], s[p[i]] = s[p[i] - 1] + 1;
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans = max(ans, s[i]);
  return cout << n - ans << '\n', 0;
}
