k = int(eval(input()))



lun_list = [1,2,3,4,5,6,7,8,9]



for i in lun_list:

    if str(i)[-1] == '0':

        for j in range(2):

            lun_list.append(int(str(i)+str(j)))

    elif str(i)[-1] == '9':

        for j in range(8,10):

            lun_list.append(int(str(i)+str(j)))

    else:

        for j in range(int(str(i)[-1])-1,int(str(i)[-1])+2):

            lun_list.append(int(str(i)+str(j)))

    if len(lun_list) > k:

        break



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



num_list = [1,2,3,4,5,6,7,8,9]

num_a = ['0', '1']

num_b = ['8', '9']



for i in num_list:

    if str(i)[-1] == '0':

        for j in num_a:

            num_list.append(int(str(i)+j))

    elif str(i)[-1] == '9':

        for j in num_b:

            num_list.append(int(str(i)+j))

    else:

        num = int(str(i)[-1])

        for j in range(num-1, num+2):

            num_list.append(int(str(i)+str(j)))

    if len(num_list) > k:

        break



print((num_list[k-1]))
k = int(eval(input()))
lun_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in lun_list:
    if str(i)[-1] == "0":
        for j in range(2):
            lun_list.append(int(str(i) + str(j)))
    elif str(i)[-1] == "9":
        for j in range(8, 10):
            lun_list.append(int(str(i) + str(j)))
    else:
        for j in range(int(str(i)[-1]) - 1, int(str(i)[-1]) + 2):
            lun_list.append(int(str(i) + str(j)))
    if len(lun_list) > k:
        break
print((lun_list[k - 1]))

k = int(eval(input()))
num_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
num_a = ["0", "1"]
num_b = ["8", "9"]
for i in num_list:
    if str(i)[-1] == "0":
        for j in num_a:
            num_list.append(int(str(i) + j))
    elif str(i)[-1] == "9":
        for j in num_b:
            num_list.append(int(str(i) + j))
    else:
        num = int(str(i)[-1])
        for j in range(num - 1, num + 2):
            num_list.append(int(str(i) + str(j)))
    if len(num_list) > k:
        break
print((num_list[k - 1]))

-lun_list = [1, 2, 3, 4, 5, 6, 7, 8, 9] -for i in lun_list: +num_list = [1, 2, 3, 4, 5, 6, 7, 8, 9] +num_a = ["0", "1"] +num_b = ["8", "9"] +for i in num_list: -        for j in range(2): -            lun_list.append(int(str(i) + str(j))) +        for j in num_a: +            num_list.append(int(str(i) + j)) -        for j in range(8, 10): -            lun_list.append(int(str(i) + str(j))) +        for j in num_b: +            num_list.append(int(str(i) + j)) -        for j in range(int(str(i)[-1]) - 1, int(str(i)[-1]) + 2): -            lun_list.append(int(str(i) + str(j))) -    if len(lun_list) > k: +        num = int(str(i)[-1]) +        for j in range(num - 1, num + 2): +            num_list.append(int(str(i) + str(j))) +    if len(num_list) > k: -print((lun_list[k - 1])) +print((num_list[k - 1]))