Problem:
Score : 400 points

Problem Statement

A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:

In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.

For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.

You are given a positive integer K. Find the K-th smallest lunlun number.

Constraints

1 \leq K \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K

Output

Print the answer.

Sample Input 1

15

Sample Output 1

23

We will list the 15 smallest lunlun numbers in ascending order:

1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
21,
22,
23.

Thus, the answer is 23.

Sample Input 2

1

Sample Output 2

1

Sample Input 3

13

Sample Output 3

21

Sample Input 4

100000

Sample Output 4

3234566667

Note that the answer may not fit into the 32-bit signed integer type.

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace ABC161
{
    public class Solve
    {
        public static void Main(string[] args)
        {
            new ABC_D();
        }
    }
    public class ABC_A
    {
        public ABC_A()
        {
            var i = Ex.ReadIntArray();
            Ex.Cw($"{i[2]} {i[0]} {i[1]}");
        }
    }
    public class ABC_B
    {
        public ABC_B()
        {
            var l1 = Ex.ReadIntArray();
            var arr = Ex.ReadIntArray();
            // N 種類の商品
            var n = l1[0];
            // M個を選べる
            var m = l1[1];
            // 総投票数の1/4M未満である
            ulong d = 0;
            foreach (var v in arr) d += (ulong)(v / 4.0 / m);
            var c = arr.Count(v => d < (ulong)v);
            Ex.Cw(m <= c);
        }
        public void Cw(bool b)
        {
            if (b) Ex.Cw("Yes");
            else Ex.Cw("No");
        }
    }
    public class ABC_C
    {
        public ABC_C()
        {
            var l1 = Ex.ReadLongArray();
            // Nの初期値
            var n = l1[0];
            // Kの差の絶対値で置き換える
            var k = l1[1];

            var a = n % k;
            Ex.Cw(Math.Min(a, Math.Abs(a - k)));
        }
    }
    public class ABC_D
    {
        /// <summary>
        /// 小さい方からK番目のルンルン数
        /// </summary>
        long k;
        long n = 0;
        long end = 0;
        char[] arr;
        long cou = 0;

        public ABC_D()
        {
            k = Ex.ReadLong;

            long idx = 0;
            long d = 8;
            long e = 1;
            long pre = 0;
            while (n < k)
            {
                pre = n;
                idx++;
                if (idx != 1)
                {
                    d = check(d);
                    e = checkedge(e);
                }
                n += d;
                n += e;
            }

            cou = pre;
            end = idx;
            arr = new char[end];
            for (int i = 1; i <= 9; i++)
            {
                dfs(0, i);
            }
        }

        long check(long pre)
        {
            n += 3 * pre;
            return 3 * pre;
        }

        long checkedge(long pre)
        {
            n += 2 * pre;
            return 2 * pre;
        }

        void dfs(long idx, int t)
        {
            arr[idx] = (char)('0' + t);
            if (end == (idx + 1))
            {
                cou++;
                if (cou == k)
                {
                    Console.WriteLine(arr);
                }
                return;
            }
            if (cou >= k)
            {
                return;
            }


            if (t == 0)
            {
                dfs(idx + 1, 0);
                dfs(idx + 1, 1);
                return;
            }

            if (t == 9)
            {
                dfs(idx + 1, 8);
                dfs(idx + 1, 9);
                return;
            }
            dfs(idx + 1, t - 1);
            dfs(idx + 1, t);
            dfs(idx + 1, t + 1);
            return;
        }
    }
    public class ABC_E
    {
        public ABC_E()
        {
        }
    }
    public class ABC_F
    {
        public ABC_F()
        {

        }
    }
    public static class Ex
    {
        public static void Cw(object s)
        {
            Console.WriteLine(s);
        }
        public static void Cw(bool b)
        {
            if (b) Cw("Yes");
            else Cw("No");
        }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(s => int.Parse(s)).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(s => long.Parse(s)).ToArray(); }
        public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}