target_word = gets.chomp.downcase
count = 0

while sentense = gets.chomp
  break if sentense == "END_OF_TEXT"
  words = sentense.split.map(&:downcase)
  count += words.count(target_word)
end

puts count