import queue

q=queue.Queue()



K=int(eval(input()))

for i in range(1,10):q.put(i)

while(not q.empty()):

    a=q.get()

    K-=1

    if K==0:

        print(a)

        exit()

    for i in range(a%10-1,a%10+1+1):

        if i<0 or i>9:continue

        q.put(a*10+i)











import collections

ans=[]

s=collections.deque()

k=int(eval(input()))

ans.append(1)

for i in range(1,k):

    for x in str(ans[i-1]):

        s.append(int(x))

    ls=len(s)-1

    while ls>=0 and s[ls]==9:

        s[ls]=0

        ls-=1

    if ls==-1:s.appendleft(1)

    else:s[ls]+=1

    while True:

        b=-1

        for i in range(0,len(s)-1):

            if abs(s[i+1]-s[i])>1:

                b=i

                break

        if b==-1:break

        if s[b+1]>s[b]:s[b]+=1

        l=max(s[b]-1,0)

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

            s[i]=l

            l=max(l-1,0)

    #print(s)

    t=0

    while len(s)>=1:

        x=s.popleft()

        #print("*",x)

        t=t*10+x

    ans.append(t)

print((ans[k-1]))



























import queue

q = queue.Queue()
K = int(eval(input()))
for i in range(1, 10):
    q.put(i)
while not q.empty():
    a = q.get()
    K -= 1
    if K == 0:
        print(a)
        exit()
    for i in range(a % 10 - 1, a % 10 + 1 + 1):
        if i < 0 or i > 9:
            continue
        q.put(a * 10 + i)

import collections

ans = []
s = collections.deque()
k = int(eval(input()))
ans.append(1)
for i in range(1, k):
    for x in str(ans[i - 1]):
        s.append(int(x))
    ls = len(s) - 1
    while ls >= 0 and s[ls] == 9:
        s[ls] = 0
        ls -= 1
    if ls == -1:
        s.appendleft(1)
    else:
        s[ls] += 1
    while True:
        b = -1
        for i in range(0, len(s) - 1):
            if abs(s[i + 1] - s[i]) > 1:
                b = i
                break
        if b == -1:
            break
        if s[b + 1] > s[b]:
            s[b] += 1
        l = max(s[b] - 1, 0)
        for i in range(b + 1, len(s)):
            s[i] = l
            l = max(l - 1, 0)
    # print(s)
    t = 0
    while len(s) >= 1:
        x = s.popleft()
        # print("*",x)
        t = t * 10 + x
    ans.append(t)
print((ans[k - 1]))

-import queue +import collections -q = queue.Queue() -K = int(eval(input())) -for i in range(1, 10): -    q.put(i) -while not q.empty(): -    a = q.get() -    K -= 1 -    if K == 0: -        print(a) -        exit() -    for i in range(a % 10 - 1, a % 10 + 1 + 1): -        if i < 0 or i > 9: -            continue -        q.put(a * 10 + i) +ans = [] +s = collections.deque() +k = int(eval(input())) +ans.append(1) +for i in range(1, k): +    for x in str(ans[i - 1]): +        s.append(int(x)) +    ls = len(s) - 1 +    while ls >= 0 and s[ls] == 9: +        s[ls] = 0 +        ls -= 1 +    if ls == -1: +        s.appendleft(1) +    else: +        s[ls] += 1 +    while True: +        b = -1 +        for i in range(0, len(s) - 1): +            if abs(s[i + 1] - s[i]) > 1: +                b = i +                break +        if b == -1: +            break +        if s[b + 1] > s[b]: +            s[b] += 1 +        l = max(s[b] - 1, 0) +        for i in range(b + 1, len(s)): +            s[i] = l +            l = max(l - 1, 0) +    # print(s) +    t = 0 +    while len(s) >= 1: +        x = s.popleft() +        # print("*",x) +        t = t * 10 + x +    ans.append(t) +print((ans[k - 1]))