import Control.Monad

main = print =<< (pure (ans . (\[_, b] -> b))) <*> (replicateM 2 getLine)

getInts :: IO [Int]
getInts = (pure ((map read) . words)) <*> getLine

ans :: String -> Int
ans [] = 0
ans [_] = 0
ans [_, _] = 0
ans ('A':'B':'C':xs) = 1 + (ans xs)
ans (_:xs) = ans xs
