N = gets.to_i
a,ba,b = 0,0,0
ans = 0
N.times do |i|
  s = gets.chomp
  (s.length-1).times do |i|
    ans += 1 if s[i] == "A" && s[i+1] == "B"
  end
  if s[0] == "B" && s[-1] == "A"
    ba += 1
  elsif s[0] == "B"
    b += 1
  elsif s[-1] == "A"
    a += 1
  end
end
ans += [a,b].min
if ba > 0
  ans += ba-1
  ans += 1 if a+b > 0
end
p ans
