n = gets.to_i
w = x = y = z = 0
n.times do |i|
  s = gets.chomp
  if s[0] == "B"
    if s[-1] == "A"
      x += 1
    else
      y += 1
    end
  elsif s[-1] == "A"
    z += 1
  end
  w += s.scan("AB").size
end
if [x, y, z].max == y
  w += x
  w += z
elsif [x, y, z].max == z
  w += x
  w += y
else
  w += x
end
puts w