#include <bits/stdc++.h>
using namespace std;

const int N=300005;

typedef long long LL;

int k,h,t;
vector<LL> num;
LL Q[N];

void work()
{h=t=0;
 for (int i=1;i<=9;i++)
   Q[++t]=i;
 while (h<t)
   {LL cur=Q[++h];
    int x=cur%10;
	if (x!=0) Q[++t]=cur*10ll+x-1;
	Q[++t]=cur*10ll+x;
	if (x!=9) Q[++t]=cur*10ll+x+1;
    if (t>=k) break;
   }
}

int main()
{
 cin>>k;
 work();
 cout<<Q[k]<<endl;
 return 0;
}
