#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; vector a(N); rep(i,N) cin >> a[i]; vector l; rep(i,N) { auto it = lower_bound(l.begin(), l.end(), a[i]); if(it == l.end()) l.push_back(a[i]); else *it = a[i]; } cout << N - (int)l.size() << endl; }