n = gets.to_i
ss = []
ab_count = 0
la_count = 0
fb_count = 0
lafb_count = 0
n.times do
  s = gets.chomp
  (0..s.size-2).each do |i|
    if s[i..i+1] == 'AB'
      ab_count += 1
    end
  end
  if s[-1] == 'A' && s[0] == 'B'
    if la_count > fb_count
      fb_count += 1
    else
      la_count += 1
    end
  else
    la_count += 1 if s[-1] == 'A'
    fb_count += 1 if s[0] == 'B'
  end
end
puts ab_count + [la_count, fb_count].min