#include <bits/stdc++.h>

using namespace std;

signed
main(void)
{
    int n;
    cin >> n;

    if (n == 0) {
        cout << 0 << endl;
        return 0;
    }

    vector<int> a(n);
    for (auto &i : a) {
        cin >> i;
    }

    reverse(a.begin(), a.end());

    const int INF = 1e9 + 1e8;
    vector<int> d(n + 1, INF);
    d[0] = -INF;

    for (int i = 0; i < n; i++) {
        int l = upper_bound(d.begin(), d.end(), a[i]) - d.begin();
        if (d[l - 1] <= a[i] && a[i] < d[l]) {
            d[l] = a[i];
        }
    }

    int ans = 0;
    for (int l = 0; l <= n; l++) {
        if (d[l] < INF) {
            ans = l;
        }
    }

    int punish = n - ans;
    cout << punish << endl;

    return 0;
}
