import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

type Triple = (Int, Maybe (Maybe Char, Char))

main :: IO ()
main = do
  (n : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  s <- getLine :: IO String
  let
    step :: Triple -> Char -> Triple
    step (k, Nothing) c = (k, Just (Nothing, c))
    step (k, Just (Just 'A', 'B')) 'C' = (succ k, Nothing)
    step (k, Just (_, c')) c = (k, Just (Just c', c))
  print . fst . T.foldl step (0, Nothing) $ s

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
