N = gets.to_i
ss = $stdin.readlines.map(&:chomp)
 
ab_count = ss.map {|s| s.scan(/AB/).length }.inject(:+)
a_end_count = ss.select {|s| s[-1] == 'A' }.length
b_beg_count = ss.select {|s| s[0] == 'B' }.length
 
ans = ab_count + [a_end_count, b_beg_count].min
puts ans