Function to count