n = gets.to_i
s = []
b_head_num = 0
a_tail_num = 0
ab_num = 0

def get_ab_num(s)
    count = 0
    (0..(s.length - 2)).each do |i|
        count += 1 if s[i] == 'A' and s[i+1] == 'B'
    end
    count
end

(0...n).each do |i|
    input = gets.strip
    b_head_num += 1 if input[0] == 'B'
    a_tail_num += 1 if input[-1] == 'A'
    ab_num += get_ab_num(input)
    s.append input
end
print ab_num + [n - 1, b_head_num, a_tail_num].min