n = gets.chomp!.to_i

s_n = Array.new(n, "")
ab_count = 0
a_count = 0
b_count = 0

n.times do |i|
    s_n[i] = gets.chomp!
    ab_count += s_n[i].scan("AB").count

    if s_n[i][0] == 'B' 
        b_count += 1
    end
    if s_n[i][-1] == 'A'
        a_count += 1
    end
end

count =  ab_count + [a_count, b_count].min
if [a_count, b_count].min == n
    count -= 1
end
puts count
