n = gets.chomp.to_i
ary = []
n.times do
    ary << gets.chomp
end

ab_count = 0
a_count = 0
b_count = 0
ary.each do |str|
    # 文字列に含まれるABの数をcountします
    for i in 0..(str.length-2)
        if str[i] == "A"
            if str[i+1] == "B"
                ab_count += 1
            end
        end
    end
    if str[-1] == "A"
        a_count += 1
    end
    if str[0] == "B"
        b_count += 1
    end
end
min = [a_count, b_count].min
min -= 1 if min == n
puts(ab_count + min)