import Data.List
import Control.Monad

main :: IO ()
main = do
  n <- readLn :: IO Int
  ss <- replicateM n getLine
  let baseac = length $ filter (isInfixOf "AB") ss
      lasta  = length $ filter (isSuffixOf "A") ss
      firstb = length $ filter (isPrefixOf "B") ss
      -- lasta  = length $ filter (not . isPrefixOf "B") $ filter (isSuffixOf "A") ss
      -- firstb = length $ filter (not . isSuffixOf "A") $ filter (isPrefixOf "B") ss
--      bothab = length $ filter (isSuffixOf "A")       $ filter (isPrefixOf "B") ss
  print $ baseac + min lasta firstb
