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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

///God is great

#include <bits/stdc++.h>
using namespace std;

/************************** definations *******************************/
#define pi              2*acos(0.0)
#define ll              long long int
#define llu             unsigned long long
#define sc(a)           scanf("%d",&a)
#define scc(a,b)        scanf("%d %d",&a,&b)
#define sccc(a,b,c)     scanf("%d %d %d",&a,&b,&c)
#define sc1(a)          scanf("%lld",&a)
#define sc2(a,b)        scanf("%lld %lld",&a,&b)
#define sc3(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define sc4(a,b,c,d)    scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define pf1(a)          printf("%lld\n",a)
#define pf2(a,b)        printf("%lld %lld\n",a,b)
#define Case(a)         printf("Case %d: ",a)
#define Casel(a)        printf("Case %lld: ",a)
#define mem(a,x)        memset(a,x,sizeof(a))
#define INF             1<<29
#define Inf             10000
#define inf             INT_MAX
#define INFL            1e18
#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair
#define NL              cout << endl;
#define DONE            cerr << "Done" << endl
#define PAUSE           system("pause")
#define DEBUG(x)        cerr << #x << " = " << x << endl
#define READ            freopen("input.txt", "r", stdin)
#define WRITE           freopen("output.txt", "w", stdout)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pii             pair<int,int>
#define ii              pair<ll,int>
#define M               10000007
#define mod             100000007
#define Mod             1000000007
#define MAX             1001
#define qk              5000000
#define REP(i,x,m)      for(i=x;i<m;i++)
#define vi              vector<int>
/************************** definations *******************************/
int main()
{
    /*#ifndef ONLINE_JUDGE
    READ;
    WRITE;
    #endif*/
    FASTIO;
    llu i,k;
    cin >> k; k--;
    queue <llu> q;
    REP(i,1,10) q.push(i);
    while(k--){
        llu op = q.front(); q.pop();
      	llu m = op%10;
        if(m!=0) q.push(10*op + m - 1);
        q.push(10*op + m);
        if(m!=9) q.push(10*op + m + 1);
    }
    cout << q.front();
}