// Beginner161.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

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

typedef  long long ll;

//ll getResult(ll n, ll k)
//{
//	if (k == 1 || n == k) return 0;
//	if (n > k)
//	{
//		auto div = n / k;
//		return min(abs(n - div * k), abs(n - (div+1)*k));
//	}
//	else
//	{	
//		return min(n, k-n);
//	}
//}

void getNextNumber(string& number)
{
	bool allNine = true;
	for (int i = 0; i < number.size(); ++i)
	{
		if (number[i] != '9')
		{
			allNine = false;
			break;
		}
	}

	if (allNine)
	{
		string zeros(number.size(), '0');
		number = "1" + zeros;
		return;
	}
	
	for (int i = number.size() - 1; i > 0; --i)
	{
		if (number[i] - number[i-1] < 1)
		{
			string c = to_string(number[i] - '0' + 1);
			number[i] = c[0];
			return;
		}
	}
	int startNumer = number[0] - '0' + 1;
	for (int i = 0; i < number.size(); ++i)
	{
		int curNumber = max(0, startNumer - i);
		string c = to_string(curNumber);
		number[i] = c[0];
	}
	
}

void getGraphs(const string& s, int k, int c, vector<vector<int>>& graphs, vector<int>& curGraph, int curPos, 
	map<int, vector<vector<int>>>& mem_graphs)
{
	if (curGraph.size() == k)
	{
		graphs.push_back(curGraph);
		return;
	}

	if (mem_graphs.count(curPos) > 0)
	{
		
	}

	for (int i = curPos + 1; i < s.size(); ++i)
	{
		if (s[i] == 'x') continue;
		if (!curGraph.empty() && i - curPos <= c) continue;
		vector<int> g1 = curGraph;
		g1.push_back(i);
		getGraphs(s, k, c, graphs, g1, i, mem_graphs);
	}
}

bool f(long long x, long long y)
{
	while (x % y == 0)
	{
		x /= y;
	}
	return x % y == 1;
}

int main()
{
    //A
	/*int a, b, c;
	cin >> a >> b >> c;
	cout << c << ' ' << a << ' ' << b << '\n';*/

	//B
	/*int n, m;
	cin >> n >> m;
	vector<int> a(n);

	int c = 0;
	double t = 1.0 / (4 * m);

	int sum = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		sum += a[i];
	}
	for (int i = 0; i < n; ++i)
	{
		double aCoef = a[i] * 1.0 / sum;
		if (aCoef >= t) c++;
	}
	
	cout << (c >= m ? "Yes" : "No");*/


	//C
	/*ll n, k;
	cin >> n >> k;

	auto result = getResult(n, k);
	cout << result;*/

	//D


	int k;
	cin >> k;
	if (k <= 12) {
		cout << k;
		return 0;
	}
	priority_queue<ll, vector<ll>, greater<ll>> pq;
	for (int i = 1; i <= 9; i++)
		pq.push(i);

	int cnt = 0;
	ll ans;
	while (true) {
		ll num = pq.top();
		pq.pop();
		cnt++;

		if (cnt == k) {
			ans = num;
			break;
		}

		int ld = num % 10;
		ll num1 = num * 10 + ld;
		pq.push(num1);

		if (ld != 0) {
			num1 = num * 10 + ld - 1;
			pq.push(num1);
		}
		if (ld != 9) {
			num1 = num * 10 + ld + 1;
			pq.push(num1);
		}
	}
	cout << ans;


	//E
	//int n, k, c;
	//cin >> n >> k >> c;
	//string s;
	//cin >> s;

	//map<int, vector<vector<int>>> mem_graphs; //графы 

	//vector<vector<int>> graphs;
	//vector<int> curGraph;
	//getGraphs(s, k, c, graphs, curGraph, -1, mem_graphs);

	//vector<bool> workDays(n, true);
	//for (int i = 0; i < n; ++i)
	//{
	//	if (s[i] == 'x') workDays[i] = false;
	//}

	//if (graphs.empty()) return 0;

	//vector<int> res = graphs[0];
	//
	//for (int i = 0; i < graphs.size(); ++i)
	//{
	//	vector<int> tmp;
	//	set_intersection(res.begin(), res.end(), graphs[i].begin(), graphs[i].end(),
	//		back_inserter(tmp));
	//	res = tmp;
	//}

	//for (auto& item:res)
	//{
	//	cout << item + 1 << '\n';
	//}
	//


	//F
	//ll n;
	//cin >> n;
	//if (n == 2)
	//{
	//	cout << 2;
	//	return 0;
	//}

	//int s = 0;
	//int t = 0;
	//for (ll i = 2; i * i <= n; ++i)
	//{
	//	if (n % i == 0)
	//	{
	//		t++;
	//		
	//		int tmp = n;
	//		while (tmp % i == 0) tmp /= i;
	//		if (tmp % i == 1) s++;
	//	}
	//	if (n % i == 1) s++;
	//	//if (n % i == 0) 
	//}
	//
	//cout << s + t;
}



Measured memory_bytes: 2420