let w = read_line() ;;
let t =
  let rec f(s) =
    let a = read_line() |> (fun x -> (^) x " ") in
    if a = "END_OF_TEXT " then s
    else f (s ^ String.lowercase a)
  in
  f("") ;;

let tl = Str.split (Str.regexp " ") t;;

let () =
  let f x xs = List.fold_left (fun e y -> if x = y then (e + 1) else e) 0 xs in
  Printf.printf "%d\n" (f w tl);;
