n = gets.chomp.to_i
words = []
ab_strings = []
start_b_strings= []
end_a_strings = []
for i in 0..n-1
  words[i] = gets.chomp
  ab_strings.push(words[i]) if !words[i].index("AB").nil?
  start_b_strings.push(words[i]) if words[i][0] == "B"
  end_a_strings.push(words[i]) if words[i][-1] == "A"
end

pre_ab_string_length = [end_a_strings.length, start_b_strings.length].min

print("#{ab_strings.length + pre_ab_string_length}\n")