def max_child( money, children):
        # cannot give 1 to each child
        if money < children:
            return -1
        # have more than 8 to each child, all children have 8 except 1 child have more
        if money > 8 * children: 
            return children - 1
        # give 1 to every child first
        money -= children
        # find the number of child to reach 8 and the extra amount
        res = money // 7
        extra = money % 7
        # if amount is 3 and only one child is not 8, we need another child to seperate money to avoid child having 4
        if extra == 3 and res  == children-1 :
             return res - 1
        # return  result
        return res
print (max_child (20 , 3))
#print (max_child (16 , 2))