N = gets.to_i
a = 0
b = 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"
}

if a == N and b == N
  ans += N -1
else
  ans += a > b ? b : a
end

puts ans
