// D - Lunlun Number
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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