n = gets.to_i

firstB, lastA = 0, 0
count = 0
duplicate = 0

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

#puts "firstB:#{firstB}, lastA:#{lastA}, dup:#{duplicate}"

if duplicate == 0
  count += [firstB, lastA].min
else
  if firstB == duplicate && lastA == duplicate
    count += duplicate - 1
  else
    count += [firstB, lastA].min
  end
end
puts count