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

static class LIS {
    struct D : IComparable<D> {
        public int value;
        public int index;
        public int CompareTo(D o) {
            return value.CompareTo(o.value);
        }
    }

    public static List<int> Do(List<int> xs) {
        var lis = new List<D>();
        lis.Add(new D { value=xs[0], index=0 });

        var prev = new int[xs.Count];
        for (int i = 1; i < xs.Count; i++) {
            var d = new D { value=xs[i], index=i };
            int p = lis.BinarySearch(d);
            if (p < 0) {
                int m = ~p;
                if (m == lis.Count) lis.Add(d);
                else lis[m] = d;

                if (m == 0) prev[i] = -1;
                else prev[i] = lis[m-1].index;
            }
        }

        var ret = new List<int>();
        int index = lis.Last().index;
        while (index != -1) {
            ret.Add(xs[index]);
            index = prev[index];
        }
        ret.Reverse();
        return ret;
    }
}

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

    static void Main() {
        int n = ReadInt();
        var xs = new List<int>();
        for (int i = 0; i < n; i++) {
            xs.Add(ReadInt());
        }

        var ans = LIS.Do(xs);
        Console.WriteLine(ans.Count);
    }
}