import Data.Char

countElem :: Eq a => a -> [a] -> Int
countElem _ [] = 0
countElem x (x':xs) = (if x == x' then 1 else 0) + (countElem x xs)

getUntil :: String -> IO [String]
getUntil eot = do
  let loop list = do
        ws <- fmap words getLine
        if ws == [eot] then return list
        else loop (list ++ ws)
  loop []

main :: IO ()
main = do
  w <- fmap (map toLower) getLine
  t <- fmap (map (map toLower)) $ getUntil "END_OF_TEXT"
  print $ countElem w t