n = gets.to_i
ss = []
n.times do
  ss << gets.chomp
end
ab_count = ss.count { |s| s.include? 'AB' }
la_count = ss.count { |s| s[-1] == 'A' }
fb_count = ss.count { |s| s[0] == 'B' }
# puts ab_count
# puts la_count
# puts fb_count
puts ab_count + [la_count, fb_count].min