#include using namespace std; int main() { int n; cin >> n; vector a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector dp; for (int x : a) { auto it = lower_bound(dp.begin(), dp.end(), x); if (it == dp.end()) { dp.push_back(x); } else { *it = x; } } cout << n - dp.size() << endl; return 0; }