#include<iostream>
#include <algorithm>
#include<queue>
using namespace std;

int k;

int main()
{
	cin >> k;
	queue<long long> q;
	for (int i = 1; i <= 9; i++)
		q.push(i);
	for (int i = 1; i < k; i++)
	{
		long long x = q.front();
		long long m = x % 10;
		if (m != 0)
			q.push(x * 10 + m - 1);
		q.push(x * 10 + m);
		if (m != 9)
			q.push(x * 10 + m + 1);
		q.pop();
	}
	cout << q.front() << endl;
	return 0;
}