P18129 [ICPC 2026 Seoul R] Stepping Numbers

Description

A positive integer is called a stepping number if, in its decimal representation without leading zeros, the absolute difference between every pair of adjacent digits is exactly $1$. For example, both an increasing step (a $2$ following a $1$) and a decreasing step (a $1$ following a $2$) are allowed. A single-digit number (from $1$ to $9$) has no adjacent pair to compare, so it is also considered a stepping number. For example, $10$, $21$, $123432$, and $56565$ are stepping numbers. On the other hand, $11$ (difference $0$), $13$ (difference $2$), and $100$ (its last two digits $0$ and $0$ have difference $0$) are not stepping numbers. Given an integer $n$, you must find the $n$-th smallest stepping number.

Input Format

Your program is to read from standard input. The input consists of a single line containing one integer $n$ ($1\le n\le 10^5$).

Output Format

Your program is to write to standard output. Print the $n$-th smallest stepping number on a single line. It is guaranteed that the answer is less than $10^{15}$, so it fits in a signed 64-bit integer.