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

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static int Len(int[] xs) {
        int n = xs.Length;
        var dp = new int[n + 1];
        for (int i = 0; i < dp.Length; i++)
            dp[i] = int.MaxValue;

        foreach (int x in xs) {
            int p = Array.BinarySearch(dp, x);
            if (p < 0) {
                dp[~p] = x;
            }
        }
        int m = Array.BinarySearch(dp, int.MaxValue);
        return m < 0 ? ~m : m + 1;
    }

    static void Main() {
        int n = ReadInt();
        var xs = new int[n];
        for (int i = 0; i < n; i++) {
            xs[i] = ReadInt();
        }

        var ans = Len(xs);
        Console.WriteLine(ans);
    }
}