# coding: utf-8

# Your code here!

from collections import deque

k=int(eval(input()))

ans=[]

d=deque([1,2,3,4,5,6,7,8,9])

c=0

while c<11:

    q=d.popleft()

    ans.append(q)

    c=len(str(q))

    b=q%10

    if b!=0:

        d.append(q*10+b-1)

    d.append(q*10+b)

    if b!=9:

        d.append(q*10+b+1)

    

print((ans[k-1]))
# coding: utf-8

# Your code here!

from collections import deque

k=int(eval(input()))

ans=[]

d=deque([1,2,3,4,5,6,7,8,9])

c=0

while c<100100:

    q=d.popleft()

    ans.append(q)

    c+=1

    b=q%10

    if b!=0:

        d.append(q*10+b-1)

    d.append(q*10+b)

    if b!=9:

        d.append(q*10+b+1)

    

print((ans[k-1]))
# coding: utf-8
# Your code here!
from collections import deque

k = int(eval(input()))
ans = []
d = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
c = 0
while c < 11:
    q = d.popleft()
    ans.append(q)
    c = len(str(q))
    b = q % 10
    if b != 0:
        d.append(q * 10 + b - 1)
    d.append(q * 10 + b)
    if b != 9:
        d.append(q * 10 + b + 1)
print((ans[k - 1]))

# coding: utf-8
# Your code here!
from collections import deque

k = int(eval(input()))
ans = []
d = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
c = 0
while c < 100100:
    q = d.popleft()
    ans.append(q)
    c += 1
    b = q % 10
    if b != 0:
        d.append(q * 10 + b - 1)
    d.append(q * 10 + b)
    if b != 9:
        d.append(q * 10 + b + 1)
print((ans[k - 1]))

-while c < 11: +while c < 100100: -    c = len(str(q)) +    c += 1