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

namespace ConsoleTest
{
    static partial class Program
    {
        static int _count = 9;
        static int _k = 0;
        static List<string> Create2(List<string> seed, string adder, bool isCount)
        {
            var result = new List<string>();
            foreach(var s in seed)
            {
                string combined = adder + s;
                if (isCount)
                {
                    _count++;
                    //Console.WriteLine(string.Format("[{0}]{1}", _count, combined));
                    if (_k == _count)
                    {
                        //Console.WriteLine(string.Format("[{0}]{1}", _count, combined));
                        //Console.WriteLine(string.Format("Found !!"));
                        Console.WriteLine(combined);
                        throw new FoundException();
                    }
                }
                else
                {
                    //Console.WriteLine(string.Format("[--]{0}", combined));
                }
                result.Add(combined);
            }
            return result;
        }
        
        static List<string>[] CreateNextLunLun(List<string>[] seed)
        {
            var result = new List<string>[10];
            for(int i = 0; i < 10; ++i)
            {
                if (i == 0) result[i] = Create2(seed[0], "0", false).Concat(Create2(seed[1], "0", false)).ToList();
                else if (i == 9) result[i] = Create2(seed[8], "9", true).Concat(Create2(seed[9], "9", true)).ToList();
                else result[i] = Create2(seed[i - 1], i.ToString(), true).Concat(Create2(seed[i], i.ToString(), true)).Concat(Create2(seed[i+1], i.ToString(), true)).ToList();
            }
            return result;
        }

        static void Main(string[] args)
        {
            _k = Int();
            if (_k < 10)
            {
                Console.WriteLine(_k);
                return;
            }
            var seed = new List<string>[10];
            for(int i = 0; i < 10; ++i)
            {
                seed[i] = new List<string>();
                seed[i].Add(i.ToString());
            }
            try
            {
                for (int i = 0; i < 100; ++i)
                {
                    seed = CreateNextLunLun(seed);
                    //Console.WriteLine(string.Format("DumpSeed keta {0}", i));
                    //DumpSeed(seed);
                }

            }
            catch (FoundException)
            {
                // do nothing.
            }
        }
        static void DumpSeed(List<string>[] seed)
        {
            for(int i = 0; i < seed.Length; ++i)
            {
                foreach(var s in seed[i])
                {
                    Console.WriteLine(s);
                }
            }

        }
        class FoundException : Exception
        {

        }
           
    }
    static partial class Program
    {
        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }
        public static int[] Ints()
        {
            return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        }
        public static long[] Longs()
        {
            return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
        }
        public static int[][] MultiInts(int num)
        {
            var result = new int[num][];
            for(int i = 0; i < num; ++i)
            {
                result[i] = Ints();
            }
            return result;
        }
        public static T[] MultiItems<T>(int num, Func<string,T> parser)
        {
            var result = new T[num];
            for(int i =0; i < num; ++i)
            {
                result[i] = parser(Console.ReadLine());
            }
            return result;
        }
    }
}


Measured memory_bytes: 26076