#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n;
int main(){
	cin>>n;
	queue<ll> q;
	for (ll i=1;i<=9;i++) 
	    q.push(i);
	while(!q.empty()){
		ll x=q.front(); 
		q.pop(); 
		n--;
		if(!n){a
			cout<<x;
			break;
		}
		for(ll y=(x%10)-1;y<=(x%10)+1;y++){
			if(y<0||y>9) continue;
			q.push(x*10+y);
		}
	}
	return 0;
}