    n = get_i
    c = 0
    bb = 0
    ea = 0
    bo = 0
    for i in 1..n
      t = gets.chomp.gsub("AB", "-")
      c += t.count("-")
      b = 0
      if t[0] == "B"
        bb += 1
        b += 1
      end
      if t[-1] == "A"
        ea += 1
        b += 1
      end
      if b == 2
        bo += 1
      end
    end
    a = [ea, bb].min
    if ea == bo && bb == bo
      c += [a - 1, 0].max
    else
      c += a
    end
    puts c