n = gets.strip.to_i
ss = n.times.map { gets.strip }

count = 0
tail_a = 0
head_b = 0

ss.each do |s|
    if s.end_with?("A")
        tail_a += 1
    end
    if s.start_with?("B")
        head_b += 1
    end
    (0..s.length-2).each do |i|
        if s[i] + s[i+1] == "AB"
            count += 1
        end
    end
end

puts count + [tail_a, head_b].min