
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int k;
  cin>>k;
  queue<ll> q;
  for(ll i = 1; i <= 9; i++)
  q.push(i);
  ll ans;
  for(int i = 0; i < k; i++){
  	ans = q.front();
    q.pop();
    if(ans%10!=0) q.push((ans*10 + ans%10 - 1));
    q.push((ans*10+ans%10));
    if(ans%10!=9) q.push((ans*10 + ans%10 + 1));
  }
  cout<<ans<<"\n";
  return 0;
}
