object Main extends App {
  override def main(args: Array[String]): Unit = {
    val listAll = io.Source.stdin.getLines.toList
    val list = listAll.drop(1)
    val w = listAll(0)
//    println(listAll)
    val res = list.takeWhile(_ != "END_OF_TEXT").
      foldLeft(0)((z, str) => {
//       println(str)
        z + str.split(' ').count(_.equalsIgnoreCase(w))
      })

    println(res)
  }
}