n = gets.to_i

ans = 0
start_with_b = 0
end_with_a = 0

s = n.times.map 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")
end

puts ans + [start_with_b, end_with_a, n-1].min
