#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long ll;

ll n, k;
queue<ll> qu;
int main() {
	cin >> n;
	for(ll i=1; i<=9; i++) qu.push(i);
	while(n--) {
		k = qu.front(); qu.pop();
		if(k % 10 > 0) qu.push(k*10 + k%10-1);
		qu.push(k*10 + k%10);
		if(k % 10 < 9) qu.push(k*10 + k%10+1);
	}
	cout << k;
	return 0;
}