import Data.Char

main = do
    w <- getLine
    ans <- countLine $ map toLower w
    putStrLn $ show ans

countLine w = do
    l <- getLine
    if (l=="END_OF_TEXT")
        then return 0
        else do
            let c1 = count w $ words $ map toLower l
            c2 <- countLine w
            return (c1 + c2)


count :: String -> [String] -> Int
count w t = length $ filter (==w) t
