using System.Collections.Generic;
using System;

public class Hello
{
    public const int INF = 999999999;
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var a = new int[n];
        for (int i = 0; i < n; i++) a[i] = int.Parse(Console.ReadLine().Trim());
        Console.WriteLine(goDP(a));
    }
    public static int goDP(int[] a)
    {
        var n = a.Length;
        var dp = new int[n];
        for (int i = 0; i < n; i++) dp[i] = INF;
        for (int i = 0; i < n; i++)
            dp[LowerBound(dp, a[i])] = a[i];
        return LowerBound(dp, INF);
    }
    public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
    {
        var low = start;
        var high = end;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (comparer.Compare(arr[mid], value) < 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    public static int LowerBound<T>(T[] arr, T value) where T : IComparable
    {
        return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
    }
}

