#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using mpint = mp::cpp_int; // 多倍長整数（任意精度）

/*
 * 定数
 */
const long double PI = (acos(-1));
const long double EPS = 1e-10;
const long long INF = 1e18;

/*
 * データ変換 
 */
/* char -> int */
int ctoi(char c) { return (int)(c - '0'); }

/*
 * 数学的な計算
 */
/* 階乗 */
int factorial(int n){ int ret = 1; for(int i = 1; i < n + 1; ++i) { ret = ret * i; } return ret; }

/* 最大公約数 */
template <typename T>T gcd(T x, T y){ return x % y == 0 ? y : gcd(y, x % y); }

/* 最小公倍数 */
template <typename T>T lcm(T a, T b) { return a * b / gcd(a, b); }

/* n個の整数の最小公倍数 */
template <typename T>T lcm_n(vector<T> &numbers) { T l; l = numbers[0]; for(int i = 1; i < numbers.size(); ++i) { l = lcm(l, numbers[i]); } return l; }

/*
 * DP向け
 */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/*
 * グラフ
 */
class Graph {
   public:
    vector<vector<int>> G;
    vector<int> Trans;
    vector<int> inDeg;
    int numV;
 
    Graph(int numV) {
        this->numV = numV;
        inDeg.assign(numV, 0);
        Trans.assign(numV, 0);
        G.assign(numV, vector<int>());
    }
 
    int topologicalSort(int v, vector<int> &dp) {
        if (dp[v] != -1) {
            return dp[v];
        }
 
        int res = 0;
 
        for (auto to : G[v]) {
            chmax(res, topologicalSort(to, dp) + 1);
        }
 
        return dp[v] = res;
    }
};

ll d[10][10]; //10桁まで

int main(){
  int k;
  cin >> k;

  d[0][0] = 0;
  d[0][1] = 1;
  d[0][2] = 1;
  d[0][3] = 1;
  d[0][4] = 1;
  d[0][5] = 1;
  d[0][6] = 1;
  d[0][7] = 1;
  d[0][8] = 1;
  d[0][9] = 1;

  int total = 9;

  if(k <= total){
    cout << k << endl;
    return 0; 
  }

  d[1][0] = 2;

  d[1][1] = 3;
  d[1][2] = 3;
  d[1][3] = 3;
  d[1][4] = 3;
  d[1][5] = 3;
  d[1][6] = 3;
  d[1][7] = 3;
  d[1][8] = 3;
  d[1][9] = 2;
  int pre_total = total;
  total = 35;
  string ans = "";

  if(k <= total){
    int diff = k - pre_total;
    int total_here = d[1][1];
    for(int i = 1; i < 9; ++i){
      if(diff <= total_here){
        ans += to_string(i);
        if(total_here - diff == 0){
          ans += to_string(i+1);
        }else if(total_here - diff == 1){
          ans += to_string(i);
        }else if(total_here - diff == 2){
          ans += to_string(i - 1);
        }
        cout << ans << endl;
        return 0;
      }
      total_here += d[1][i];
    }

    if(total_here - diff == 1){
      ans += "99";
    }else if(total_here - diff == 2){
      ans += "98";
    }
    cout << ans << endl;
    return 0; 
  }

  for(int i = 2; i < 10; ++i){
    d[i][0] = d[i-1][0] + d[i-1][1];

    for(int j = 1; j < 10; ++j){
      if(j < 9){
        d[i][j] = d[i-1][j-1] + d[i-1][j] + d[i-1][j+1];
      }else if(j == 9){
        d[i][9] = d[i-1][8] + d[i-1][9];
      }
      pre_total = total;
      total += d[i][j];
      if(k <= total){
        int digit = i;
        int num = j;
        int diff = k - pre_total;

        while(1 < digit){
          ans += to_string(num);
          if(num == 0){
            if(diff <= d[digit-1][0]){
              num = 0;
            }else if(diff <= d[digit-1][0] + d[digit-1][1]){
              diff -= d[digit-1][0];
              num = 1;
            }
          }else if( 1 <= num && num <= 8){
            if(diff <= d[digit-1][num-1]){
              num = num-1;
            }else if(diff <= d[digit-1][num-1] + d[digit-1][num]){
              diff -= d[digit-1][num-1];
              num = num;
            }else if(diff <= d[digit-1][num-1] + d[digit-1][num] + d[digit-1][num+1]){
              diff = diff - d[digit-1][num-1] - d[digit-1][num];
              num = num+1;
            }
          }else if(num == 9){
            if(diff <= d[digit-1][8]){
              num = 8;
            }else if(diff <= d[digit-1][8] + d[digit-1][9]){
              diff -= d[digit-1][8];
              num = 9;
            }
          }
          --digit;
        }

        ans += to_string(num);
        if(num == 0){
          if(diff == 1){
            ans += to_string(0);
          }else if(diff == 2){
            ans += to_string(1);
          }
        }else if(1 <= num && num <= 8){
          if(diff == 1){
            ans += to_string(num-1);
          }else if(diff == 2){
            ans += to_string(num);
          }else if(diff == 3){
            ans += to_string(num+1);
          }
        }else if(num == 9){
          if(diff == 1){
            ans += to_string(8);
          }else if(diff == 2){
            ans += to_string(9);
          }
        }
        cout << ans << endl;
        return 0;
      }
    }

  }

  return 0;
}


Measured memory_bytes: 256