$dp = Array.new 1000000
$a = Array.new 1000000
$n = 0

def solve t
    if $dp[t]
        return $dp[t]
    end
    v = 0
    max_v = 0

    for i in (t + 1..$n)
        if $a[i] > $a[t]
            v = solve i
            if v > max_v
                max_v = v
            end
        end
    end
    sum = max_v + 1
    $dp[t] = sum
    return sum
end

$n = STDIN.gets.to_i
#input = STDIN.gets.split(' ').map { |v| v.to_i }

for i in (1..$n)
    #$a[i] = input[i - 1]
    $a[i] = STDIN.gets.to_i
end
$a[0] = -1000000000
puts(solve(0) - 1)