object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val w = sc.nextLine()
  println(cntWords(sc.next(), w, makeCounter))

  def cntWords(start: String, cntWord: String, counter: () => Int): Int = {
    start match {
      case "END_OF_TEXT" => counter() - 1
      case _ =>
        if (start == cntWord) counter()
        cntWords(sc.next(), cntWord, counter)
    }
  }

  def makeCounter: () => Int = {
    var cnt = 0
    () => cnt += 1; cnt
  }
}