import scala.io.StdIn._

object Main {
  def countSearchText(s: String, n: Int = 0): Int = {
    val inputText = readLine()

    if (inputText == "END_OF_TEXT") n
    else {
      val inputTextToLower = inputText.diff("\n").split(" ").map(_.toLowerCase)
      val findTextNum = (for (i <- inputTextToLower if i == s) yield i).length
      countSearchText(s, n + findTextNum)
    }
  }

  def main(args: Array[String]) {
    val searchText = readLine()
    println(countSearchText(searchText))
  }
}