#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
5
5
1
3
2
4

or

3
1
1
1

output:
3

or

1
"""

import sys
from bisect import bisect_left


def solve():
    dis_rec = [float('inf')] * array_length
    dis_rec[0] = array[0]
    length = 1
 
    for i, ele in enumerate(array, 1):
        if dis_rec[length - 1] < ele:
            dis_rec[length] = ele
            length += 1
        else:
            position = bisect_left(dis_rec, ele)
            dis_rec[position] = ele

    return length


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    array = list(map(int, _input[1:]))
    print(solve())