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

namespace 練習問題
{
    class Program {
        static void Main(string[] args) {
            debug Debug = new debug();
            
            List<long> lunlun = new List<long>();
            int k = 0;//
            if (true) {
                k = int.Parse(Console.ReadLine());;
            } else {
                k = 100;
            }
            long rem = k;
            long num = 0;
            long ruijou = 1;
            /*
            while (rem > 0){
                num++;
                bool isLunLunFlag = isLunLun(num);
                if (isLunLunFlag == true){
                    lunlun.Add(num);
                    rem--;
                }
            }
            bool test = isLunLun(k);
            */
            //Debug.Log(test);
            long result = LunLun(k);
            Console.WriteLine(result);
        }

        static bool isLunLun(long num){
            long halve = 1;
            long numLength = num.ToString().Length;
            bool result = true;
            string numstr = num.ToString();
            for (int i = 0; i < num.ToString().Length-1; i++)
            {
                long numSubSt = long.Parse(numstr.Substring(i,1));
                Console.WriteLine(numSubSt);

                long a = long.Parse(numstr.Substring(i+1,1));
                Console.WriteLine(a);

                if (a + 1 == numSubSt){
                    result = true;
                } else if (a - 1 == numSubSt){
                    result = true;
                } else if (a == numSubSt){
                    result = true;
                } else {
                    result = false;
                    break;
                }
            }
            return result;
        }

        static long LunLun(int k){
            debug Debug = new debug();
            List<long> List_old = new List<long>();
            for (long j = 1; j < 10; j++) {
                List_old.Add(j);
            }
            // Debug.Log(List_old);
            int list_old_length = List_old.Count;
            // Debug.Log(424);
            if (list_old_length >= k){
                return List_old[k - 1];
            }
            while(true) {
                List<long> List_new = new List<long>();
                // Debug.Log("while Start");
                for (int i = 0; i < List_old.Count; i++) {
                    // Debug.Log("For Start");
                    
                    string strNum = List_old[i].ToString();
                    string LastHitoketa = strNum.Substring(strNum.Length - 1,1);
                    if (LastHitoketa == "0") {
                        // Debug.Log(12);
                        List_new.Add(long.Parse(List_old[i].ToString() + LastHitoketa));
                        List_new.Add(long.Parse(List_old[i].ToString() + LastHitoketa) + 1);
                    } else if (LastHitoketa == "9") {
                        List_new.Add(long.Parse(List_old[i].ToString() + LastHitoketa) - 1);
                        List_new.Add(long.Parse(List_old[i].ToString() + LastHitoketa));
                        // Debug.Log(21);
                    } else {
                        // Debug.Log("else");
                        // Debug.Log(List_old[i].ToString());
                        // Debug.Log(LastHitoketa);
                        List_new.Add(long.Parse(List_old[i].ToString() + LastHitoketa) - 1);
                        List_new.Add(long.Parse(List_old[i].ToString() + LastHitoketa));
                        List_new.Add(long.Parse(List_old[i].ToString() + LastHitoketa) + 1);
                        // Debug.Log(123);
                    }
                    
                    // Debug.Log(List_old);
                    // Debug.Log(List_new);
                    //return 1;
                }
                // Debug.Log("test")
                //k -= List_old.Count + 1;
                // Debug.Log("====");
                // Debug.Log(List_old);
                // Debug.Log(List_new);
                // Debug.Log(list_old_length);
                // Debug.Log(418);
                if (list_old_length + List_new.Count - 1 >= k){
                    // Debug.Log(k);
                    // Debug.Log(list_old_length);
                    // Debug.Log(List_old.Count);
                    // Debug.Log(k - list_old_length - 1);
                    // Debug.Log(List_new.Count);
                    return List_new[k - list_old_length - 1];
                }
                list_old_length += List_new.Count;
                List_old = new List<long>(List_new);

                //return 1;
                //break;
            }
            return 1;
            //  return List_old[k];
        }
/*
        static void bubble_sort(List<List<long>> a) {
            long count=0;
            for (long i = 0; i < a.Count; i++) {
                for (long j = 0; j < a.Count-i-1; j++) {
                    // if (a[j] == a[a.Count - 1]){
                    //     continue;
                    // }
                    count++;
                    if (a[j][1] > a[j+1][1]){
                        long localsave = 0;
                        localsave = a[j+1][1];
                        a[j+1][1] = a[j][1];
                        a[j][1] = localsave;
                        localsave = a[j][0];
                        a[j][0] = a[j+1][0];
                        a[j+1][0] = localsave;
                    }
                }
                //debug(a,"途中" + i);
            }
            // debug(a,"result");
            //Console.WriteLine("回数"+count);
            for (long i = 0; i < a.Count; i++)
            {
                Console.WriteLine(a[i][0]+" "+a[i][1]);
            }
        }
        /* 標準入力と標準出力が使えるかのチェック
        static void echo() {
            string echotest = Console.ReadLine();
            Console.WriteLine(echotest);
        }

        static void HelloWorld(){
            Console.WriteLine("Hello World!");
        }
        */
    }

    public class debug{
        public void Log(string str){
            Console.WriteLine(str);
        }
        public void Log(long str){
            Console.WriteLine(str);
        }
        public void Log(object obj){
            Console.WriteLine(obj);
        }

        public void Log(long[] arr){
            Console.WriteLine(string.Join(",", arr));
        }
        public void Log(string[] arr){
            Console.WriteLine(string.Join(",", arr));
        }
        public void Log(List<long> arr){
            string shuturyoku = "";
            for (int i = 0; i < arr.Count; i++) {
                shuturyoku += arr[i] + " ";
            }
            Console.WriteLine(shuturyoku.TrimEnd(' '));
        }
    }
}

Measured memory_bytes: 19280