cho.sh
Notes
Loading...

Decreasing Numbers

Time limit

2s

Memory limit

128 MB

Problem

A nonnegative integer is called a decreasing number if, when written in decimal notation, each digit is strictly smaller than the digit immediately to its left. For example, 321 and 950 are decreasing numbers, while 322 and 958 are not.

Given a positive integer N, print the N-th smallest decreasing number. The smallest decreasing number is 0, so it is the 1st one. If the N-th decreasing number does not exist, print -1.

Input

The first line contains a positive integer N. N is at most 1,000,000.

Output

Print the N-th smallest decreasing number on the first line. If it does not exist, print -1.