#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<int> arr;
int newl;
int n;
int main()
    {
    cin >> n;
    int iii;
    while (n--)
        {
            cin >> iii;
            arr.push_back(iii);
        }
    int mid = 0;
    newl = 0;
    vector<int> P (n);
    vector<int> M (n-1);
    int l = 0;
    lo = 1;
    hi = l;
    for (int i = 0;i < (n-1);i++)
        {
            while (lo <= hi)
                {
                    mid = (lo+hi)/2;
                    if (M[mid] < arr[i])
                        {
                            lo = mid + 1;
                        }
                    else
                        {
                            hi = mid + 1;
                        }
                }
            newl = lo;
            P[i] = M[newl - 1];
            M[newl] = i;
            if (newl > l)
                {
                    l = newl;
                }
        }
    cout << l;
        
    }
    
