word = gets.chomp
result = 0

loop do
    sentence = gets.downcase.chomp.split(" ").map do |s| s.to_s end
    if sentence[0] == "end_of_text"
        break
    else
        sentence.each do |n|
            if n == word
                result += 1
            end
        end
    end
end

puts result