import Control.Applicative

import Data.Char
    (isAlphaNum, toLower)
    
type Problem = (String, String)

type Result = Int

solve :: Problem -> Result

solve (word, text)
    = length $ filter (== word) list where
        lower = map toLower text
        list = map (filter isAlphaNum) $ words lower

output :: Result -> String

output
    = show
    
input :: IO Problem

input
    = do
        word <- getLine
        text <- inputText []
        return (word, text)
        
inputText :: String -> IO String

inputText text
    = do
        line <- getLine
        if line == "END_OF_TEXT"
            then return text
            else inputText $ text ++ line

main :: IO ()

main
    = putStrLn.output =<< solve <$> input