#include<bits/stdc++.h>
using namespace std;
int main(){
int k;
cin>>k;
queue<long long>que;
que.push(1);
que.push(2);
que.push(3);
que.push(4);
que.push(5);
que.push(6);
que.push(7);
que.push(8);
que.push(9);
while(que.size()){
long long s=que.front();
k--;
que.pop();
if(k==0){
cout<<s<<endl;
break;
}
int x=s%10;
int y=x-1;
int z=x+1;
if(y>=0){
que.push(s*10+y);
}
que.push(s*10+x);
if(z<=9){
que.push(s*10+z);
}
}
return 0;
}