n = gets.to_i

firstB, lastA = 0, 0
count = 0

n.times do |i|
  tmp = gets.chomp
  firstB += 1 if tmp[0] == "B"
  lastA += 1 if tmp[-1] == "A"
  count += tmp.scan("AB").length
end


count += [firstB, lastA].min
puts count