let () =
  let w = read_line () in
  let rec loop count =
    let t' = read_line () in
    if t' = "END_OF_TEXT" then count
    else
      let t = String.lowercase t' in
      let w_len, t_len = String.length w, String.length t in
      let rec crawl w_i t_i count skip =
        if t_i < t_len then
          if w_i < w_len then
            if t.[t_i] = ' ' then crawl 0 (t_i+1) count false
            else if w.[w_i] = t.[t_i] && not skip then crawl (w_i+1) (t_i+1) count false
            else crawl 0 (t_i+1) count true
          else
            let count' = if t.[t_i] = ' ' then count + 1 else count in
            crawl 0 t_i count' true
        else if w_i = w_len then count + 1 else count
      in
      loop (crawl 0 0 count false)
  in
  print_int @@ loop 0;
  print_string "\n";
;;
