n = gets.to_i

inps = []
res = 0
a_end = 0
b_begin = 0

n.times do
    inp =  gets.chomp
    res += 1 if inp.include?("AB")
    a_end += 1 if inp[-1] == 'A'
    b_begin += 1 if inp[0] == 'B'
end

res += [a_end, b_begin].min
puts res

