n = gets.to_i
ans = 0
a = b = 0
n.times do
    s = gets.chomp
    b += 1 if s[0] == "B"
    a += 1 if s[-1] == "A"
    (s.size-1).times do |i|
        ans += 1 if s[i,2] == "AB"
    end
end
puts ans+[n-1,a,b].min