N = gets.chomp.to_i
texts = []
count = 0
last_a_count = 0
first_b_count = 0
N.times do |i|
    text = gets.chomp
    count += text.scan("AB").length
    text = text.split("").map(&:to_s)
    text = [text.first,"X",text.last]
    if text.last == "A"
        last_a_count += 1
    end
    if text.first == "B"
        first_b_count += 1
    end
end
if first_b_count >= last_a_count
    puts count + last_a_count
else
    puts count + first_b_count
end
