#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<(int64_t)N;i++)
typedef int64_t LL;
int main()
{
  LL N,K,x,y,z;
  queue<LL> q;
  rep(i,9)q.push(i+1);
  cin>>K;
  rep(i,K)
  {
    x=q.front(),q.pop(),y=x%10,z=10*x+y;
    if(y!=0)q.push(z-1);
    q.push(z);
    if(y!=9)q.push(z+1);
  }
  return cout<<x<<endl,0;
}