# encoding: utf-8                                                                      

word = gets.chomp

words = { }

while line = gets.chomp and line != "END_OF_TEXT"
  line.split(/\s/).each do |w|
    if words[w].nil?
      words[w] = 1
    else
      words[w] += 1
    end
  end
end

puts words[word]