import heapq



K =int(eval(input()))



pque = []

for i in range(1, 10):

    heapq.heappush(pque, i)



for i in range(K):

    tmp = heapq.heappop(pque)

    if tmp % 10 == 0:

        heapq.heappush(pque, tmp * 10)

        heapq.heappush(pque, tmp * 10 + 1)

    elif tmp % 10 == 9:

        heapq.heappush(pque, tmp * 10 + 9)

        heapq.heappush(pque, tmp * 10 + 8)

    else:

        next_ = tmp % 10

        heapq.heappush(pque, tmp * 10 + next_ - 1)

        heapq.heappush(pque, tmp * 10 + next_)

        heapq.heappush(pque, tmp * 10 + next_ + 1)



print (tmp)

         

        

        
K = int(eval(input()))



if K <= 9:

    print (K)

    exit()



lst = [[1] * 11 for _ in range(2)]

lst_append = lst.append

lst[0][10] = 0

lst[1][0] = 0

lst[1][10] = 0



now = 9

p = 0

flag = 0

while True:

    if p == 0:

        lst[flag + 1][0] = lst[flag][0] + lst[flag][1]

        p += 1

        continue

    tmp = lst[flag][p - 1] + lst[flag][p] + lst[flag][p + 1]

    lst[flag + 1][p] = tmp

    if now + tmp >= K:

        break

    now += tmp

    p += 1



    if p == 10:

        p = 0

        flag += 1

        lst_append([0] * 11)



# print ('now', now)

# print ('p', p)

# print ('flag', flag)

# print (lst[0])

# print (lst[1])



#先頭がpでかつ現在地がnow

ans = str(p)

flag += 1

while True:

    if flag == 0:

        break

    # print (p)

    if p >= 1 and K <= now + lst[flag - 1][p - 1]:

        flag -= 1

        ans += str(p - 1)

        p -= 1

    elif K <= now + lst[flag - 1][p - 1] + lst[flag - 1][p]:

        now += lst[flag - 1][p - 1]

        flag -= 1

        ans += str(p)

    else:

        now += lst[flag - 1][p - 1] + lst[flag - 1][p]

        flag -= 1

        ans += str(p + 1)

        p += 1



print (ans)



# for tmp in lst:

#     print (tmp)

    
import heapq

K = int(eval(input()))
pque = []
for i in range(1, 10):
    heapq.heappush(pque, i)
for i in range(K):
    tmp = heapq.heappop(pque)
    if tmp % 10 == 0:
        heapq.heappush(pque, tmp * 10)
        heapq.heappush(pque, tmp * 10 + 1)
    elif tmp % 10 == 9:
        heapq.heappush(pque, tmp * 10 + 9)
        heapq.heappush(pque, tmp * 10 + 8)
    else:
        next_ = tmp % 10
        heapq.heappush(pque, tmp * 10 + next_ - 1)
        heapq.heappush(pque, tmp * 10 + next_)
        heapq.heappush(pque, tmp * 10 + next_ + 1)
print(tmp)

K = int(eval(input()))
if K <= 9:
    print(K)
    exit()
lst = [[1] * 11 for _ in range(2)]
lst_append = lst.append
lst[0][10] = 0
lst[1][0] = 0
lst[1][10] = 0
now = 9
p = 0
flag = 0
while True:
    if p == 0:
        lst[flag + 1][0] = lst[flag][0] + lst[flag][1]
        p += 1
        continue
    tmp = lst[flag][p - 1] + lst[flag][p] + lst[flag][p + 1]
    lst[flag + 1][p] = tmp
    if now + tmp >= K:
        break
    now += tmp
    p += 1
    if p == 10:
        p = 0
        flag += 1
        lst_append([0] * 11)
# print ('now', now)
# print ('p', p)
# print ('flag', flag)
# print (lst[0])
# print (lst[1])
# 先頭がpでかつ現在地がnow
ans = str(p)
flag += 1
while True:
    if flag == 0:
        break
    # print (p)
    if p >= 1 and K <= now + lst[flag - 1][p - 1]:
        flag -= 1
        ans += str(p - 1)
        p -= 1
    elif K <= now + lst[flag - 1][p - 1] + lst[flag - 1][p]:
        now += lst[flag - 1][p - 1]
        flag -= 1
        ans += str(p)
    else:
        now += lst[flag - 1][p - 1] + lst[flag - 1][p]
        flag -= 1
        ans += str(p + 1)
        p += 1
print(ans)
# for tmp in lst:
#     print (tmp)

-import heapq - -pque = [] -for i in range(1, 10): -    heapq.heappush(pque, i) -for i in range(K): -    tmp = heapq.heappop(pque) -    if tmp % 10 == 0: -        heapq.heappush(pque, tmp * 10) -        heapq.heappush(pque, tmp * 10 + 1) -    elif tmp % 10 == 9: -        heapq.heappush(pque, tmp * 10 + 9) -        heapq.heappush(pque, tmp * 10 + 8) +if K <= 9: +    print(K) +    exit() +lst = [[1] * 11 for _ in range(2)] +lst_append = lst.append +lst[0][10] = 0 +lst[1][0] = 0 +lst[1][10] = 0 +now = 9 +p = 0 +flag = 0 +while True: +    if p == 0: +        lst[flag + 1][0] = lst[flag][0] + lst[flag][1] +        p += 1 +        continue +    tmp = lst[flag][p - 1] + lst[flag][p] + lst[flag][p + 1] +    lst[flag + 1][p] = tmp +    if now + tmp >= K: +        break +    now += tmp +    p += 1 +    if p == 10: +        p = 0 +        flag += 1 +        lst_append([0] * 11) +# print ('now', now) +# print ('p', p) +# print ('flag', flag) +# print (lst[0]) +# print (lst[1]) +# 先頭がpでかつ現在地がnow +ans = str(p) +flag += 1 +while True: +    if flag == 0: +        break +    # print (p) +    if p >= 1 and K <= now + lst[flag - 1][p - 1]: +        flag -= 1 +        ans += str(p - 1) +        p -= 1 +    elif K <= now + lst[flag - 1][p - 1] + lst[flag - 1][p]: +        now += lst[flag - 1][p - 1] +        flag -= 1 +        ans += str(p) -        next_ = tmp % 10 -        heapq.heappush(pque, tmp * 10 + next_ - 1) -        heapq.heappush(pque, tmp * 10 + next_) -        heapq.heappush(pque, tmp * 10 + next_ + 1) -print(tmp) +        now += lst[flag - 1][p - 1] + lst[flag - 1][p] +        flag -= 1 +        ans += str(p + 1) +        p += 1 +print(ans) +# for tmp in lst: +#     print (tmp)