Problem:
Score : 400 points

Problem Statement

A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:

In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.

For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.

You are given a positive integer K. Find the K-th smallest lunlun number.

Constraints

1 \leq K \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K

Output

Print the answer.

Sample Input 1

15

Sample Output 1

23

We will list the 15 smallest lunlun numbers in ascending order:

1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
21,
22,
23.

Thus, the answer is 23.

Sample Input 2

1

Sample Output 2

1

Sample Input 3

13

Sample Output 3

21

Sample Input 4

100000

Sample Output 4

3234566667

Note that the answer may not fit into the 32-bit signed integer type.

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Time Limit Exceeded)

import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

public class Main {
    private static boolean slove(long i) {
        String b = i + "";
        char m[] = b.toCharArray();
        for (int j = 1; j < m.length; j++){
            if (!(m[j] - m[j - 1] == 0 || m[j] - m[j - 1] == 1 || m[j] - m[j - 1] == -1))
                return false;
        }
        return true;
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(new BufferedInputStream(System.in));
        long a[]=new long[1000];
        String p="0,21122,76667,221122,432332,565566,776767,1001012,1232232,2233211,3223212,3434343,4345456,4556555,5545433,5677899,6667654,7665434,7877666,8877789,9987676,11010111,11233334,12234321,21110101,22111101,22323433,23321212,23454543,32233222,33223223,33434432,34345545,34556566,43332211,44321101,44454432,45443232,45654323,54343323,54554344,55543222,55676544,56665443,65433232,65566544,66555444,66766566,67678777,67899987,76667876,77665656,77877888,78878876,87677677,87898788,88898998,98765666,98988876,100012110,101121210,110101210,111123343,112210001,112344332,121221234,122222222,123212210,123345654,210111100,211211010,212211212,212345443,221223210,222223333,223221112,223432322,232210100,232344344,233334432,234323323,234456567,321110111,322111111,322323443,323321222,323454545,332233232,333223233,333434434,334345555,334556654,343332221,344321111,344454434,345443234,345654333,432123454,432343456,433334322,434323221,434456543,443223444,443434567,444432101,444556787,445545665,445678989,454454321,455434565,455567877,456556777,456767899,543322345,543455667,544444567,545433445,545566765,554334322,554544565,555455665,555666678,556655656,556789987,565556765,566545665,566678989,567676767,567889898,654444454,655433332,655566566,656555544,656766666,665456654,665667667,666656567,667654433,667787877,676565677,676777656,677767665,678767788,678999876,765556655,766545555,766678878,767676665,767888998,776666543,777656545,777876555,778876678,787667787,787887889,788888877,789998887,876667654,877665434,877877666,878877789,887676677,887889878,888898767,898765444,898987789,987656543,987876545,988876676,989898887,998878887,999988766,1001011221,1001234345,1011101100,1012101223,1012322334,1100121221,1101221210,1110123432,1111223343,1112232101,1121012233,1122100010,1122321212,1123233345,1123444545,1211001100,1211232233,1212233212,1221101011,1222101221,1222322332,1223234456,1223445656,1232232121,1233222122,1233433323,1234344444,1234555543,2101000111,2101232121,2111011121,2111234323,2112234454,2121111111,2122111234,2122332123,2123322210,2123455454,2211012233,2212100010,2212321212,2221112223,2222121000,2222333234,2223323321,2223456565,2232234544,2233232332,2233443454,2234433210,2234565666,2321221211,2322222121,2323212101,2323345545,2332122344,2332343210,2333333212,2334322111,2334455433,2343222334,2343434321,2344345434,2344555677,2345544555,2345677877,3211100111,3212101111,3212322222,3221121101,3222121232,3222334321,3223332101,3223456788,3232321122,3233233333,3233444455,3234433433,3234566667";
        String x[]=p.split(",");
        for(int i=0;i<x.length;i++)
            a[i]=Long.valueOf(x[i]);
        int v=sc.nextInt();
        int b=v/400;
        long c=a[b];
        int count=v/400*400;
            for (long i = c; ; i++) {
                if (Main.slove(i)) {
                    //System.out.println(count + " " + i);
                    if (count == v) {
                        System.out.print(i);
                        break;
                    }
                    count++;
                }
            }

    }
}