searchStr = gets;

count = 0;

while true do
	
	targetStr = gets;
	
	if targetStr == "END_OF_TEXT" then
		break;
	end
	
	aryTargetStr = targetStr.split(' ');
	
	for index in 0..aryTargetStr.length-1 do
		
		count = count + aryTargetStr[index].scan(searchStr).length;
		
	end
	
end

puts count.to_s;