n = gets.to_i
last_a  = 0
first_b = 0
include_ab = 0
(0...n).each do |i|
  str = gets.chomp
  last_a += 1 if str[-1] == 'A'
  first_b += 1 if str[0] == 'B'
  include_ab += str.scan('AB').length
end
puts include_ab + [[last_a,first_b].min, n - 1].min