object Main {
  val Offset: Int = 'a' - 'A'
  val EOT: String = "END_OF_TEXT"

  def main(args: Array[String]): Unit = {
    val target = io.StdIn.readLine().toLowerCase
    val count =
      Iterator.continually(io.StdIn.readLine())
        .takeWhile(_ != EOT)
        .flatMap(toLowerCaseWords)
        .count(_ == target)

    println(count)
  }

  def toLowerCaseWords(line: String): Seq[String] = {
    import collection.mutable
    val words = mutable.Buffer.empty[String]
    var length = 0
    val buf = new Array[Char](1000 + 1)
    line.foreach { c =>
      if ('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z') {
        buf(length) = c.toLower
        length += 1
      } else if (length > 0) {
        if (length <= 10) {
          words += String.valueOf(buf.take(length))
        }
        length = 0
      }
    }
    words
  }
}