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

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

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