k = int(eval(input()))



nums = []

def inc(num):

    if num > 3234566667:

        return None

    if num <= 3234566667:

      nums.append(num)



    num_str = str(num)

    end = num_str[-1:]

    end_num = int(end)



    if end_num < 9:

        inc(int(num_str + str(end_num + 1)))

   

    inc(int(num_str + end))

    

    if end_num > 0:

        inc(int(num_str + str(end_num - 1)))



for i in range(1, 10):

    inc(i)



sort_nums = sorted(nums)

print((sorted(nums)[k - 1]))
k = int(eval(input()))



nums = []

def inc(num):

    if num > 3234566667:

        return None

    if num <= 3234566667:

      nums.append(num)



    end = str(num)[-1:]

    end_num = int(end)



    if end_num < 9:

        inc(num * 10 + end_num + 1)



    inc(num * 10 + end_num)



    if end_num > 0:

        inc(num * 10 + end_num - 1)



for i in range(1, 10):

    inc(i)



sort_nums = sorted(nums)

print((sorted(nums)[k - 1]))
k = int(eval(input()))
nums = []


def inc(num):
    if num > 3234566667:
        return None
    if num <= 3234566667:
        nums.append(num)
    num_str = str(num)
    end = num_str[-1:]
    end_num = int(end)
    if end_num < 9:
        inc(int(num_str + str(end_num + 1)))
    inc(int(num_str + end))
    if end_num > 0:
        inc(int(num_str + str(end_num - 1)))


for i in range(1, 10):
    inc(i)
sort_nums = sorted(nums)
print((sorted(nums)[k - 1]))

k = int(eval(input()))
nums = []


def inc(num):
    if num > 3234566667:
        return None
    if num <= 3234566667:
        nums.append(num)
    end = str(num)[-1:]
    end_num = int(end)
    if end_num < 9:
        inc(num * 10 + end_num + 1)
    inc(num * 10 + end_num)
    if end_num > 0:
        inc(num * 10 + end_num - 1)


for i in range(1, 10):
    inc(i)
sort_nums = sorted(nums)
print((sorted(nums)[k - 1]))

-    num_str = str(num) -    end = num_str[-1:] +    end = str(num)[-1:] -        inc(int(num_str + str(end_num + 1))) -    inc(int(num_str + end)) +        inc(num * 10 + end_num + 1) +    inc(num * 10 + end_num) -        inc(int(num_str + str(end_num - 1))) +        inc(num * 10 + end_num - 1)