You can only use digits from the given set. At each position, instead of trying -, you try only the allowed digits. observation: numbers shorter than are always valid (if they use allowed digits).
A 2-digit number made from is . For numbers with the same length as , you need the tight bound logic. Can you place digit at position without exceeding ? Transform the problem: count valid numbers by building them digit by digit from left to right.