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

namespace ForATCODER
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int K = s2i(Console.ReadLine())+1;
         var list = new List<long>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

while (true)
{
    if (list.Count() >= K)
    {
        Console.WriteLine(list[K - 2]);
        return;
    }
    else
    {
        K -= list.Count();
        var newlist = new List<long>();
        foreach (var now in list)
        {
            var d = now % 10;
            var next = now * 10;
            if (d > 0)
            {
                newlist.Add(next + d - 1);
            }
            newlist.Add(next + d);
            if (d != 9)
            {
                newlist.Add(next + d + 1);
            }
        }
        list = newlist;
    }
}

        }
        public static bool swap(int x, int y, ref int[] array)
        {

            // check for out of range
            if (array.Length <= y || array.Length <= x) return false;


            // swap index x and y
            var buffer = array[x];
            array[x] = array[y];
            array[y] = buffer;


            return true;
        }
        static int arser(int[] ar ,int search, int[] except)
        {
            for(int i  = 0;i < ar.Length;i++)
            {
                if(ar[i] == search)
                {
                    if (Array.IndexOf(except, i) >= 0) continue;
                    return i;
                }

            }
            return -1;
        }
        public static IEnumerable<int> GetDigits(int source)
        {
            int individualFactor = 0;
            int tennerFactor = Convert.ToInt32(Math.Pow(10, source.ToString().Length));
            do
            {
                source -= tennerFactor * individualFactor;
                tennerFactor /= 10;
                individualFactor = source / tennerFactor;

                yield return individualFactor;
            } while (tennerFactor > 1);
        }
        static int s2i(String s)
        {
            return Convert.ToInt32(s);
        }
        static void RESULT(double res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(long res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(ulong res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(int res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(String res)
        {
            Console.WriteLine(res);
        }
        static String[] ReadLineAll(int count)
        {
            String[] res = new String[count];
            for (int i = 0; i < count; i++)
            {
                res[i] = Console.ReadLine();
            }
            return res;
        }

        static int[] S2Iarray(String[] src)
        {
            int len = src.Length;
            int[] res = new int[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt32(src[i]);
            }
            return res;
        }
        static long[] S2Larray(String[] src)
        {
            int len = src.Length;
            long[] res = new long[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt64(src[i]);
            }
            return res;
        }
    }
}


Measured memory_bytes: 16736