import Data.Functor( (<$>))
import Data.Char( toLower, isSpace)

main = do
    w <- getLine
    t <- unlines . takeWhile ("END_OF_TEXT"/=) . lines <$> getContents
    let
	wsize = length w

	prematch con pre = (and $ zipWith (==) w con) && case pre	of
				Nothing -> True
				Just c	-> isSpace c

	search [] hit 0	_	    = hit
	search content@(c:cs) hit numRemain lastChar
	    | numRemain < wsize		    	= hit
	    | prematch content lastChar	&& isSpace (content!!wsize)
					=
						search cs (hit+1) (numRemain-1) (Just c)
	    | otherwise			    	= search cs hit (numRemain-1) (Just c)

	lt = toLower <$> t

    print $ search lt 0 (length lt) Nothing

