package main

import (
	"fmt"
	"sort"
)

var n int

func main() {
	fmt.Scan(&n)

	var arr []int
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		arr = append(arr, a)
	}

	var lis []int
	lis = append(lis, arr[0])
	for i := 1; i < len(arr); i++ {
		val := arr[i]
		if lis[len(lis)-1] < val {
			lis = append(lis, val)
		} else {
			f := func(j int) bool {
				return val < lis[j]
			}
			index := sort.Search(len(lis), f)
			if index == 0 {
				lis[0] = val
			} else {
				lis[index-1] = val
			}
		}
	}
	fmt.Println(len(lis))
}

