N = gets.to_i
s_list = N.times.map { gets.chomp.chars }
count = s_list.map do |s|
  c = 0
  prev = nil
  s.each do |ch|
    if prev == 'A' && ch == 'B'
      c += 1
    end
    prev = ch
  end
  c
end.reduce(&:+)
a_count = s_list.count do |s|
  s == ['A'] || s[-1] == 'A'
end
b_count = s_list.count do |s|
  s == ['B'] || s[0] == 'B'
end
ans = [a_count, b_count].min + count
puts ans
