n = gets.to_i
ss = n.times.map{gets.chomp}
ans = 0
b = 0 
a = 0
ba = 0
ss.each do |s|
  (0..s.size-2).each do|i|
    if s.slice(i,2) == "AB"
      ans += 1
    end
  end
  if s[0] == "B" && s[-1] == "A"
    ba += 1
  elsif s[0] == "B"
    b += 1
  elsif s[-1] == "A"
    a += 1
  end
end
ans += [a,b].min + [ba-1,0].max
if (a-b).abs > 0 && ba > 0
  ans += 1
end
puts ans