def max_children_with_eight_dollars(money, children):
    # Check if there is enough money for each child to receive at least 1 dollar
    if money < children:
        return -1  # Not enough money to give each child at least 1 dollar
    if children == 1:  # If there's only one child
        return 1 if money >= 8 else -1  # They can only receive 8 dollars if sufficient money is available

    # Calculate the maximum number of children that can receive 8 dollars
    max_children_with_8 = min(money // 8, children)

    # Iterate from the maximum possible number of children down to 0
    for k in range(max_children_with_8, -1, -1):
        remaining_money = money - k * 8  # Calculate remaining money after giving k children 8 dollars
        remaining_children = children - k  # Remaining children who need to receive money

        # Check if we can give at least 1 dollar to the remaining children
        if remaining_children > 0 and remaining_money >= remaining_children:
            return k  # Return the maximum number of children who can receive 8 dollars

    return -1  # If no valid distribution is found

# Example usage with varied outputs
print(f"Input: money = 20, children = 3 => Output: {max_children_with_eight_dollars(20, 3)}")  # Output: 1
print(f"Input: money = 16, children = 2 => Output: {max_children_with_eight_dollars(16, 2)}")  # Output: 2
print(f"Input: money = 25, children = 4 => Output: {max_children_with_eight_dollars(25, 4)}")  # Output: 2
print(f"Input: money = 40, children = 6 => Output: {max_children_with_eight_dollars(40, 6)}")  # Output: 4
print(f"Input: money = 10, children = 3 => Output: {max_children_with_eight_dollars(10, 3)}")  # Output: -1