let () =
    let main () =
        let n = int_of_string (read_line ()) in
        let find_index arr v col =
            let rec loop l r =
                if l = r then l else
                    let m = (l + r) / 2 in
                    if arr.(m) >= v then loop (m + 1) r else
                                         loop l m
            in
            loop 1 col
        in
        let rec loop arr i col =
            if i = 0 then col else
                let p = int_of_string (read_line ()) in
                if p <= arr.(col) then (
                    let col = col + 1 in
                    arr.(col) <- p;
                    loop arr (i - 1) col
                ) else (
                    let j = find_index arr p col in
                    let () = arr.(j) <- p in
                    loop arr (i - 1) col
                )
        in
        let arr = Array.make (n + 1) 0 in
        let () = arr.(1) <- int_of_string (read_line ()) in
        Printf.printf "%d\n" (loop arr (n - 1) 1)
    in
    main ()