using System;
using System.Collections.Generic;
using System.Text;

namespace AOJ
{
    class Program
    {
        static bool isSeparator(char c)
        {
            switch (c)
            {
                case ' ':
                    return  true;
                case '\r':
                case '\n':
                    return  true;
            }
            return false;
        }
        static int skipSeparator(char[] text, int index)
        {
            for (; index < text.Length; ++index)
            {
                if (isSeparator(text[index]) == false)
                {
                    break;
                }
            }
            return index;
        }
        static int skipNotSeparator(char[] text, int index)
        {
            for (; index < text.Length; ++index)
            {
                if (isSeparator(text[index]) == true)
                {
                    break;
                }
            }
            return index;
        }

        // textの中からwordを探すことを試みて、作業した箇所までをiTextEndsで返す。
        // 一つ一つ文字を分割したほうがわかりやすいがなんとなくこの形にしてみた。
        static bool tryFind(char[] text, int iTextStarts, out int iTextEnds, char[] word)
        {
            iTextStarts = skipSeparator(text, iTextStarts);
            iTextEnds = skipNotSeparator(text, iTextStarts);
            if (iTextEnds - iTextStarts < word.Length)
            {
                return false;
            }

            for (int iWord = 0, iText = iTextStarts; iWord < word.Length; ++iWord, ++iText)
            {
                if (word[iWord] != text[iText])
                {
                    return false;
                }
            }

            return true;
        }
        static int countWord(char[] text, char[] word)
        {
            int count = 0;
            for (int iTextStarts = 0, iTextEnds = 0; iTextStarts < text.Length; iTextStarts = iTextEnds)
            {
                iTextStarts = skipSeparator(text, iTextStarts);
                iTextEnds = skipNotSeparator(text, iTextStarts);
                if (iTextEnds - iTextStarts != word.Length)
                {
                    continue;
                }

                bool mismatched = false;
                for (int iWord = 0, iText = iTextStarts; iWord < word.Length; ++iWord, ++iText)
                {
                    if (word[iWord] != text[iText])
                    {
                        mismatched = true;
                        break;
                    }
                }
                if (mismatched == false)
                {
                    ++count;
                }
            }
            return count;
        }

        static void Main(string[] args)
        {
            var word = Console.In.ReadLine().ToCharArray();

            var text = new List<string>();

            for(;;)
            {
                var input = Console.In.ReadLine();
                if (input == "END_OF_TEXT")
                {
                    break;
                }
                text.Add(input);
            }

            int wordCount = 0;
            foreach (var line in text)
            {
                var textChars = line.ToLower().ToCharArray();
                wordCount += countWord(textChars, word);
            }

            Console.Out.WriteLine(wordCount);
        }
    }
}



Measured memory_bytes: 15876