words=[]
gets.chomp.to_i.times do
  words << gets.chomp
end

count = 0
aend = 0
bstart = 0
for i in 0..(words.count - 1) do
  alph = words[i].split("")
  if alph[0] == "B"
    bstart +=1
  end
  if alph[-1] == "A"
    aend +=1
  end
  for j in 0..(alph.count - 2) do
    if alph[j] == "A" && alph[j + 1] == "B"
      count += 1
    end
  end
end

if aend >= bstart
  count += bstart
else
  count += aend
end

puts count
