#K47357. Smallest Positive Integer with Given Digit Sum

    ID: 28180 Type: Default 1000ms 256MiB

Smallest Positive Integer with Given Digit Sum

Smallest Positive Integer with Given Digit Sum

Given a target integer \(n\), your task is to find the smallest positive integer \(x\) such that the sum of its digits is exactly \(n\). If no such number exists, output \(-1\). Note that \(n\) must satisfy \(1 \le n \le 100\); otherwise, the answer is defined to be \(-1\).

For example:

  • If \(n=15\), the smallest number with digits summing to 15 is 69.
  • If \(n=4\), the answer is 4 itself.
  • If \(n=27\), the answer is 999.

Construct the number by selecting digits greedily from the maximum allowable digit (9) and then ordering them in ascending order to ensure minimality.

inputFormat

The input consists of a single line containing one integer \(n\) (\(1 \le n \le 100\)).

outputFormat

Output the smallest positive integer whose digit sum equals \(n\). If such a number does not exist, output \(-1\).

## sample
15
69