n = gets.chomp.to_i
ss = (0...n).map { gets.chomp }

ab = ss.map { |s| s.scan('AB').length }.inject(&:+)
xa = ss.select { |s| s[0] != 'B' && s[-1] == 'A' }.length
ba = ss.select { |s| s[0] == 'B' && s[-1] == 'A' }.length
bx = ss.select { |s| s[0] == 'B' && s[-1] != 'A' }.length

if xa == 0 && bx == 0
  if ba == 0
    puts(ab)
  else
    puts(ab + ba - 1)
  end
else
  puts(ab + ba + [xa, bx].min)
end
