k=int(eval(input()))

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

for _ in range(9):

    tmp=[]

    for val in cand[-1]:

        s=str(val)

        if s[-1]=='0':

            tmp.append(val*10)

            tmp.append(val*10+1)

        elif s[-1]=='9':

            tmp.append(val*10+8)

            tmp.append(val*10+9)

        else:

            tmp.append(val*10+(int(s[-1])-1))

            tmp.append(val*10+(int(s[-1])))

            tmp.append(val*10+(int(s[-1])+1))

    cand.append(tmp)

ans=[]

for i in range(len(cand)):

    for val in cand[i]:

        ans.append(val)

ans=sorted(ans)

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

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

for _ in range(9):

  tmp=[]

  for val in cand[-1]:

    if val%10!=0:

      tmp.append(val*10+(val%10-1))

    tmp.append(val*10+(val%10))

    if val%10!=9:

      tmp.append(val*10+(val%10+1))

  cand.append(tmp)

ans=[]

for i in range(len(cand)):

  for val in cand[i]:

    ans.append(val)

ans=sorted(ans)

print((ans[k-1]))
k = int(eval(input()))
cand = [[1, 2, 3, 4, 5, 6, 7, 8, 9]]
for _ in range(9):
    tmp = []
    for val in cand[-1]:
        s = str(val)
        if s[-1] == "0":
            tmp.append(val * 10)
            tmp.append(val * 10 + 1)
        elif s[-1] == "9":
            tmp.append(val * 10 + 8)
            tmp.append(val * 10 + 9)
        else:
            tmp.append(val * 10 + (int(s[-1]) - 1))
            tmp.append(val * 10 + (int(s[-1])))
            tmp.append(val * 10 + (int(s[-1]) + 1))
    cand.append(tmp)
ans = []
for i in range(len(cand)):
    for val in cand[i]:
        ans.append(val)
ans = sorted(ans)
print((ans[k - 1]))

k = int(eval(input()))
cand = [[1, 2, 3, 4, 5, 6, 7, 8, 9]]
for _ in range(9):
    tmp = []
    for val in cand[-1]:
        if val % 10 != 0:
            tmp.append(val * 10 + (val % 10 - 1))
        tmp.append(val * 10 + (val % 10))
        if val % 10 != 9:
            tmp.append(val * 10 + (val % 10 + 1))
    cand.append(tmp)
ans = []
for i in range(len(cand)):
    for val in cand[i]:
        ans.append(val)
ans = sorted(ans)
print((ans[k - 1]))

-        s = str(val) -        if s[-1] == "0": -            tmp.append(val * 10) -            tmp.append(val * 10 + 1) -        elif s[-1] == "9": -            tmp.append(val * 10 + 8) -            tmp.append(val * 10 + 9) -        else: -            tmp.append(val * 10 + (int(s[-1]) - 1)) -            tmp.append(val * 10 + (int(s[-1]))) -            tmp.append(val * 10 + (int(s[-1]) + 1)) +        if val % 10 != 0: +            tmp.append(val * 10 + (val % 10 - 1)) +        tmp.append(val * 10 + (val % 10)) +        if val % 10 != 9: +            tmp.append(val * 10 + (val % 10 + 1))