k = int(eval(input()))

n = 0



def ff(s, i):

    for j in range(i+1, len(s)):

        #print(s[j-1])

        if s[j-1] > 0:

            s[j] = s[j-1] - 1

        else:

            s[j] = 0

    return s



def next(s):

    ls = len(s)

    for i in range(ls-1, 0, -1):

        if s[i-1] >= s[i] and s[i] != 9:

            s[i] += 1

            #print(s[i-1],s[i])

            return ff(s, i)

    if s[0] == 9:

        return [1] + ([0] * ls)

    else:

        s[0] += 1

        return ff(s, 0)



if k < 10:

    print(k)

    exit()



ans = [1,0]

for i in range(k - 10):

    ans = next(ans)

#print(ans)

print((''.join(map(str, ans))))









k = int(eval(input()))

r = [[i] for i in range(1,10)]



from collections import deque

que = deque(r)



if k < 10:

    print(k)

    exit()

while len(r) <= k:

    ri = que.popleft()

    for j in range(max(0, ri[-1]-1), min(9, ri[-1]+1)+1):

        rj = ri.copy()

        rj.append(j)

        r.append(rj)

        que.append(rj)

        #print(que)

#print(r[k-1])

print((''.join(map(str, r[k-1]))))



k = int(eval(input()))
n = 0


def ff(s, i):
    for j in range(i + 1, len(s)):
        # print(s[j-1])
        if s[j - 1] > 0:
            s[j] = s[j - 1] - 1
        else:
            s[j] = 0
    return s


def next(s):
    ls = len(s)
    for i in range(ls - 1, 0, -1):
        if s[i - 1] >= s[i] and s[i] != 9:
            s[i] += 1
            # print(s[i-1],s[i])
            return ff(s, i)
    if s[0] == 9:
        return [1] + ([0] * ls)
    else:
        s[0] += 1
        return ff(s, 0)


if k < 10:
    print(k)
    exit()
ans = [1, 0]
for i in range(k - 10):
    ans = next(ans)
# print(ans)
print(("".join(map(str, ans))))

k = int(eval(input()))
r = [[i] for i in range(1, 10)]
from collections import deque

que = deque(r)
if k < 10:
    print(k)
    exit()
while len(r) <= k:
    ri = que.popleft()
    for j in range(max(0, ri[-1] - 1), min(9, ri[-1] + 1) + 1):
        rj = ri.copy()
        rj.append(j)
        r.append(rj)
        que.append(rj)
        # print(que)
# print(r[k-1])
print(("".join(map(str, r[k - 1]))))

-n = 0 +r = [[i] for i in range(1, 10)] +from collections import deque - -def ff(s, i): -    for j in range(i + 1, len(s)): -        # print(s[j-1]) -        if s[j - 1] > 0: -            s[j] = s[j - 1] - 1 -        else: -            s[j] = 0 -    return s - - -def next(s): -    ls = len(s) -    for i in range(ls - 1, 0, -1): -        if s[i - 1] >= s[i] and s[i] != 9: -            s[i] += 1 -            # print(s[i-1],s[i]) -            return ff(s, i) -    if s[0] == 9: -        return [1] + ([0] * ls) -    else: -        s[0] += 1 -        return ff(s, 0) - - +que = deque(r) -ans = [1, 0] -for i in range(k - 10): -    ans = next(ans) -# print(ans) -print(("".join(map(str, ans)))) +while len(r) <= k: +    ri = que.popleft() +    for j in range(max(0, ri[-1] - 1), min(9, ri[-1] + 1) + 1): +        rj = ri.copy() +        rj.append(j) +        r.append(rj) +        que.append(rj) +        # print(que) +# print(r[k-1]) +print(("".join(map(str, r[k - 1]))))