A number is called elegant if, for all 0 = d = 9, the digit d does not appear more than d times. For example, the number 3 cannot appear more than 3 times in an elegant number (and the digit 0 cannot appear at all).
How many positive 4-digit elegant numbers exist? Some numbers to include are 1345, 5999, 6554, and 7828.