N = gets.to_i

Ss = []

a = 0
b = 0
ba = 0

sum = 0

N.times do
  s = gets.chomp
  
  sum += s.scan('AB').length

  if s[0] == "B" && s[s.length-1] == "A"
    ba += 1
  elsif s[0] == "B"
    b += 1
  elsif s[s.length-1] == "A"
    a += 1
  end
end

sum += [a, b].min
sum += ba


puts sum
