$n = gets.to_i
$a = Array.new($n) {
    gets.to_i
}

$x = []
$count_set = 0
$min_count = $n
def solve(j)
    if j >= $n then
        if $min_count > $count_set then
            $min_count = $count_set
        end
        return
    end
    for i in 0...$count_set
        if $x[i][-1] < $a[j] then
            $x[i].push($a[j])
            solve(j + 1)
            $x[i].pop
        end
    end
    $x.push([$a[j]])
    $count_set += 1
    solve(j + 1)
    $x.pop
    $count_set -= 1
end

solve(0)
puts $min_count
