n = gets.to_i
words = Array.new(n).map {gets.upcase.chomp}

n_ab = words.inject(0) {|nn, w| nn + (w.match(/AB/) || []).size}
b_a = words.find_all {|w| w =~ /^B\w*A$/}
b_x = words.find_all {|w| w =~ /^B\w*[^A]$/}
x_a = words.find_all {|w| w =~ /^[^B]\w*A$/}
result = if b_a.empty?
           n_ab + [b_x.size, x_a.size].min
         else
           n_ab + b_a.size + [b_x.size, x_a.size].min
         end

puts result