import scala.io.StdIn.readLine

object Main extends App {

  val t     = readLine()
  val lines = Iterator.continually(readLine()).takeWhile { _ != "END_OF_TEXT" }

  val allWords = for {
    line <- lines
    words = line.split(" ")
    word <- words
  } yield word.toLowerCase

  val cnt = allWords.count { _ == t }
  println(cnt)
}

