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)

#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

set<ll>sset;
ll mas=3234566667;
map<string,int>used;
void dfs(string t){
	int n=t.size();
	int last=t[n-1]-'0';
	deque<string>cand;
	rep(i,3){
		string now=t;
		int d=-1+i;
		if(last+d>=0&&last+d<10){
			now.push_back('0'+last+d);
		}
		ll num=stoll(now);
	//	cout<<num<<endl;
		if(mas>=num){
			sset.insert(num);
			cand.push_back(now);
		}
	}
	rep(i,cand.size()){
		if(!used[cand[i]]){
			used[cand[i]]++;
			dfs(cand[i]);
		}
	}
	

}

void solve()
{
	int n;
	cin>>n;
/*	vector<vector<char>>next(10);
	rep(i,10){
		next[i].push_back('0'+i);
	}
	FOR(i,0,9){
		next[i].push_back('0'+i+1);
	}
	FOR(i,1,10){
		next[i].push_back('0'+i-1);
	}
	rep(i,10){
		rep(j,next[i].size()){
		//	cout<<next[i][j];
		}
		cout<<endl;
	}
	*/
	rep(i,9){
		string m="0";
		m[0]+=i+1;
		//cout<<m<<endl;
		sset.insert(i+1);
		dfs(m);
	}
	auto i=sset.begin();
	int cnt=0;
	ll ans;
	while(i!=sset.end()){
		//cout<<*i<<endl;
		if(cnt==n-1){
			ans=*i;
			break;
		}
		i++;
		cnt++;
	}
	cout<<ans<<endl;

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}