n = gets.chomp.to_i
s = n.times.map{gets.chomp}
count = 0
s.each do |si|
  pos = 0
  len = si.length
  bef = ""
  len.times do |i|
    count += 1 if bef == "A" && si[i] == "B"
    bef =  si[i]
  end
end

countOA = 0
countBO = 0
countBA = 0

s.each do |si|
  if si[0] == "B" && si[-1] == "A" then
    countBA += 1
  elsif si[0] == "B" then
    countBO += 1
  elsif si[-1] == "A" then
    countOA += 1
  end
end

countBA -= 1 if [countBO, countOA].max == 0 && countBA != 0

puts count + countBA + [countBO, countOA].min
