let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  List.rev (doit str [])

let count_words w t =
  List.length (List.filter (fun s -> s = w) (split t ' '))

let () =
  try
    let w = read_line () in
    let rec doit cnt =
      match read_line () with
      | "END_OF_TEXT" -> Printf.printf "%d\n" cnt
      | t -> doit (cnt + count_words (String.lowercase_ascii w) (String.lowercase_ascii t))
    in
    doit 0
  with End_of_file -> ()