let words str =
  let len = String.length str in
  let rec aux start stop =
    if stop >= len || str.[stop] = ' '
    then String.sub str start (stop-start), stop+1
    else aux start (stop+1)
  in
  let rec iter i l =
    if len-i <= 0 then l
    else
      match str.[i] with
        ' ' -> iter (i+1) l
      | _ ->
        let s,j = aux i (i+1) in
        iter j (s::l)
  in iter 0 []
 
let () =
  let w = read_line () in
  let rec loop count =
    match read_line () with
      "END_OF_TEXT" -> Printf.printf "%d\n" count
    | s -> loop (words s
                 |> List.fold_left
                   (fun acc x ->
                      acc +
                      (if String.lowercase x = String.lowercase w then 1 else 0))
                   0
                 |> (+) count)
  in loop 0