#include <bits/stdc++.h>

using namespace std;

#define intt long long

int main() {

	int k;
	cin >> k;
	queue <intt> q;
	for (int i = 1; i <= 9; i ++) {
		q.push(1LL * i);
	}
	while (-- k) {
		intt x = q.front();
		q.pop();
		if (x % 10 != 0) {
			q.push(x * 10 + x % 10 - 1);
		}
		q.push(10 * x + x % 10);
		if (x % 10 != 9) {
			q.push(x * 10 + x % 10 + 1);
		}
	}
	cout << q.front() << '\n';
	return 0;
}