def add():

    for i in ans[cnt-1]:

        i=str(i)

        last=i[-1]

        last=int(last)

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

            if j==10 or j==-1:

                continue

            tmp=i

            tmp+=str(j)

            ans[cnt].append(int(tmp))



n=int(eval(input()))

ans=[[]for i in range(10)]

cnt=1

for i in range(1,10):

    ans[0].append(i)



for i in range(9):

    add()

    cnt+=1

merged=[]

for i in ans:

    merged+=i

merged=sorted(merged)

print((merged[n-1]))
def dfs(x):

    ans.append(x)

    if len(str(x))==10:

        return

    

    last=x%10

    

    for i in [last-1,last,last+1]:

        if 0<=i<=9:

            dfs(10*x+i)



k=int(eval(input()))

ans=[]

for i in range(1,10):

    dfs(i)

    

ans=sorted(ans)

print((ans[k-1]))



def add():
    for i in ans[cnt - 1]:
        i = str(i)
        last = i[-1]
        last = int(last)
        for j in range(last - 1, last + 2):
            if j == 10 or j == -1:
                continue
            tmp = i
            tmp += str(j)
            ans[cnt].append(int(tmp))


n = int(eval(input()))
ans = [[] for i in range(10)]
cnt = 1
for i in range(1, 10):
    ans[0].append(i)
for i in range(9):
    add()
    cnt += 1
merged = []
for i in ans:
    merged += i
merged = sorted(merged)
print((merged[n - 1]))

def dfs(x):
    ans.append(x)
    if len(str(x)) == 10:
        return
    last = x % 10
    for i in [last - 1, last, last + 1]:
        if 0 <= i <= 9:
            dfs(10 * x + i)


k = int(eval(input()))
ans = []
for i in range(1, 10):
    dfs(i)
ans = sorted(ans)
print((ans[k - 1]))

-def add(): -    for i in ans[cnt - 1]: -        i = str(i) -        last = i[-1] -        last = int(last) -        for j in range(last - 1, last + 2): -            if j == 10 or j == -1: -                continue -            tmp = i -            tmp += str(j) -            ans[cnt].append(int(tmp)) +def dfs(x): +    ans.append(x) +    if len(str(x)) == 10: +        return +    last = x % 10 +    for i in [last - 1, last, last + 1]: +        if 0 <= i <= 9: +            dfs(10 * x + i) -n = int(eval(input())) -ans = [[] for i in range(10)] -cnt = 1 +k = int(eval(input())) +ans = [] -    ans[0].append(i) -for i in range(9): -    add() -    cnt += 1 -merged = [] -for i in ans: -    merged += i -merged = sorted(merged) -print((merged[n - 1])) +    dfs(i) +ans = sorted(ans) +print((ans[k - 1]))