k = int(eval(input()))

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



while 1:

    if k<=len(a):

        print((a[k-1]))

        exit()

    b=[]

    for i in a:

        if i[-1]!='0':

            b.append(i+chr(ord(i[-1])-1))

        b.append(i+i[-1])

        if i[-1]!='9':

            b.append(i+chr(ord(i[-1])+1))

    k-=len(a)

    a=b.copy()
k = int(eval(input()))

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



while k>len(a):

    b=[]

    for i in a:

        if i[-1]!='0':

            b.append(i+chr(ord(i[-1])-1))

        b.append(i+i[-1])

        if i[-1]!='9':

            b.append(i+chr(ord(i[-1])+1))

    k-=len(a)

    a=b.copy()



print((a[k-1]))
k = int(eval(input()))
a = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
while 1:
    if k <= len(a):
        print((a[k - 1]))
        exit()
    b = []
    for i in a:
        if i[-1] != "0":
            b.append(i + chr(ord(i[-1]) - 1))
        b.append(i + i[-1])
        if i[-1] != "9":
            b.append(i + chr(ord(i[-1]) + 1))
    k -= len(a)
    a = b.copy()

k = int(eval(input()))
a = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
while k > len(a):
    b = []
    for i in a:
        if i[-1] != "0":
            b.append(i + chr(ord(i[-1]) - 1))
        b.append(i + i[-1])
        if i[-1] != "9":
            b.append(i + chr(ord(i[-1]) + 1))
    k -= len(a)
    a = b.copy()
print((a[k - 1]))

-while 1: -    if k <= len(a): -        print((a[k - 1])) -        exit() +while k > len(a): +print((a[k - 1]))