using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int[] A = new int[n];

            for (int i = 0; i < n; i++)
            {
                A[i] = int.Parse(Console.ReadLine());
            }

            Console.WriteLine(GetLIS(A));
        }

        static int GetLIS(int[] A)
        {
            const int INFTY = int.MaxValue;
            int n = A.Length;

            int[] L = Enumerable.Repeat(INFTY, n).ToArray();
            int[] id = new int[n];
            int ret = 0;

            for (int i = 0; i < n; i++)
            {
                id[i] = LowerBound(L, A[i]);
                L[id[i]] = A[i];
            }

            return id.Max() + 1;
        }

        static int LowerBound(int[] arr, int value)
        {
            int low = 0;
            int high = arr.Length;
            int mid;

            while (low < high)
            {
                mid = ((high - low) >> 1) + low;        // (low + high) / 2
                if (arr[mid] < value) low = mid + 1;
                else high = mid;
            }
            return low;
        }
    }
}