import sys
import bisect

def lis(arr):
    queue = []
    queue.append(arr[0])
    for num in arr[1:]:
        if num > queue[-1]:
            queue.append(num)
        else:
            idx = bisect.bisect_left(queue, num)
            queue[idx] = num
    return len(queue)
    
    
if __name__ == '__main__':
    N = sys.stdin.readline()
    N = int(N)
    arr = []
    for i in range(N):
        tmp = sys.stdin.readline()
        arr.append(int(tmp))
    
    sys.stdout.write(str(lis(arr)))
    sys.stdout.write('\n')
    