N = gets.to_i
a = 0
b = 0
ba = 0
ans = 0
N.times { 
  str = gets.chop
  ans += str.scan(/AB/).count
  a += 1  if str[-1] == "A"
  b += 1  if str[0] == "B"
  ba += 1 if str[0] == "B" and str[-1] == "A"
}

if ba > 0
  if a == ba and b == ba
    a -= 1
    b -= 1
  end
end

ans += a > b ? b : a


puts ans