n = gets.to_i

ans = 0
start_with_b = 0
end_with_a = 0
ba = 0

n.times do 
  ss = gets.chomp
  ans += ss.scan("AB").count
  start_with_b += 1 if ss.start_with?("B")
  end_with_a += 1 if ss.end_with?("A")
  ba += 1 if ss.start_with?("B") && ss.end_with?("A")
end

if start_with_b == end_with_a && start_with_b == ba
  puts ans + (ba-1 >= 0 ? ba-1 : 0)
else
  puts ans + [start_with_b, end_with_a].min
end
