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

public class AtCoderD
{
    static void Main()
    {
        var sc = new Scanner();

        int k = sc.NextInt();

        List<long> nums = new List<long>();

        int count = 0;
        for (int i = 1; i <= 9; i++)
        {
            nums.Add(i);
            count++;
            if (count == k)
            {
                Console.WriteLine(i);
                return;
            }
        }

        int start = 0;
        while (true)
        {
            int size = nums.Count();
            for (int i = start; i < size; i++)
            {
                long num = nums[i];
                long one = num % 10;
                if (one == 0)
                {
                    nums.Add(num * 10 + one);
                    count++;
                    if (count == k)
                    {
                        Console.WriteLine(nums.Last());
                        return;
                    }
                    nums.Add(num * 10 + one + 1);
                    count++;
                    if (count == k)
                    {
                        Console.WriteLine(nums.Last());
                        return;
                    }
                }
                else if (one == 9)
                {
                    nums.Add(num * 10 + one - 1);
                    count++;
                    if (count == k)
                    {
                        Console.WriteLine(nums.Last());
                        return;
                    }
                    nums.Add(num * 10 + one);
                    count++;
                    if (count == k)
                    {
                        Console.WriteLine(i);
                        return;
                    }
                }
                else
                {
                    nums.Add(num * 10 + one - 1);
                    count++;
                    if (count == k)
                    {
                        Console.WriteLine(nums.Last());
                        return;
                    }
                    nums.Add(num * 10 + one);
                    count++;
                    if (count == k)
                    {
                        Console.WriteLine(nums.Last());
                        return;
                    }
                    nums.Add(num * 10 + one + 1);
                    count++;
                    if (count == k)
                    {
                        Console.WriteLine(nums.Last());
                        return;
                    }
                }
            }
            start = size;
        }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13320