#include #define REP(i, n) for (int i = 0; (i) < int(n); ++ (i)) using namespace std; template vector longest_increasing_subsequence(vector const & xs) { vector l; // l[i] is the last element of the increasing subsequence whose length is i+1 l.push_back(xs.front()); for (auto && x : xs) { auto it = lower_bound(l.begin(), l.end(), x); if (it == l.end()) { l.push_back(x); } else { *it = x; } } return l; } int main() { // input int n; cin >> n; vector a(n); REP (i, n) cin >> a[i]; // solve REP (i, n) a[i] -= 1; int answer = n - longest_increasing_subsequence(a).size(); // output cout << answer << endl; return 0; }