#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
using ll=long long;
using namespace std;
const ll mod=1e9+7;
int main(){
    ll k;
    cin>>k;
    queue<ll> x;
    rep(i,1,10)x.push(i);
    while(k>=0){
        ll y=x.front();
        x.pop();
        if(y%10>0)x.push(y*10+y%10-1);
        x.push(y*10+y%10);
        if(y%10<9)x.push(y*10+y%10+1);
        k--;
        if(k==0)cout<<y;
    }
}