open Printf
open Scanf

let n = sscanf (read_line ()) "%d" (fun n -> n);;
let array = Array.make n 0;;
Array.iteri (fun x _ -> array.(x) <- read_int()) array;;

let ans_tuple = (0,Array.make 200000 (-1));;

let isOK index key array_tuple =
    let (size, array) = array_tuple in
    if (array.(index) > key) then true
    else false;;

let binary_search key array_tuple =
    let (size, array) = array_tuple in
    let left = ref (-1) in
    let right = ref (size) in
    while (!right - !left > 1) do
        let mid = !left + (!right - !left) / 2 in
        if isOK mid key array_tuple then
        right := mid
        else
        left := mid
    done;
    !right;;

let array_update key array_tuple =
let (size, target) = array_tuple in
let index = binary_search key array_tuple in
if size = 0 then
    (*let _ = printf("size:0 key = %d, index = %d\n") key index in*)
    let _ = target.(0) <- key in
    (size + 1, target)
else if index = size then
   (*let _ = printf("index=size key = %d, index = %d\n") key index in*)
    if key < target.(index-1) then
        let _ = target.(index-1) <- key in
        (size, target)
    else
        let _ = target.(index) <- key in
        (size + 1, target)
else
(*let _ = printf("replace key = %d, index = %d\n") key index in *)
    let _ = target.(index) <- key in
    (size, target);;

let rec solve n array_tuple =
    let (size, target) = array_tuple in
    if n < 0 then size
    else
        let l = array_update array.(n) array_tuple in
        solve (n-1) l;;

printf ("%d\n") (solve (n-1) ans_tuple);;