pattern = gets.strip

s_array = gets.downcase.split(" ")
s_tmp = gets
until s_tmp === "END_OF_TEXT"
	s_array.concat(s_tmp.downcase.split(" "))
	s_tmp = gets
end 
p s_array
puts s_array.grep(pattern).length
