# Original solution
c = 0
K = int(eval(input()))
for i in range(1,10):
    c += 1
    if c == K:
        print(i)

for i in range(1,10):
    for j in range(i-1,min(i+2,10)):
        c += 1
        if c == K:
            print((10*i+j))

for i in range(1,10):
    for j in range(i-1,min(i+2,10)):
        for k in range(max(j-1,0),min(j+2,10)):
            c += 1
            if c == K:
                print((100*i+10*j+k))

for i in range(1,10):
    for j in range(i-1,min(i+2,10)):
        for k in range(max(j-1,0),min(j+2,10)):
            for l in range(max(k-1,0),min(k+2,10)):
                c += 1
                if c == K:
                    print((1000*i+100*j+10*k+l))

for i in range(1,10):
    for j in range(i-1,min(i+2,10)):
        for k in range(max(j-1,0),min(j+2,10)):
            for l in range(max(k-1,0),min(k+2,10)):
                for m in range(max(l-1,0),min(l+2,10)):
                    c += 1
                    if c == K:
                        print((10000*i+1000*j+100*k+10*l+m))

for i in range(1,10):
    for j in range(i-1,min(i+2,10)):
        for k in range(max(j-1,0),min(j+2,10)):
            for l in range(max(k-1,0),min(k+2,10)):
                for m in range(max(l-1,0),min(l+2,10)):
                    for n in range(max(m-1,0),min(m+2,10)):
                        c += 1
                        if c == K:
                            print((100000*i+10000*j+1000*k+100*l+10*m+n))

for i in range(1,10):
    for j in range(i-1,min(i+2,10)):
        for k in range(max(j-1,0),min(j+2,10)):
            for l in range(max(k-1,0),min(k+2,10)):
                for m in range(max(l-1,0),min(l+2,10)):
                    for n in range(max(m-1,0),min(m+2,10)):
                        for o in range(max(n-1,0),min(n+2,10)):
                            c += 1
                            if c == K:
                                print((1000000*i+100000*j+10000*k+1000*l+100*m+10*n+o))

for i in range(1,10):
    for j in range(i-1,min(i+2,10)):
        for k in range(max(j-1,0),min(j+2,10)):
            for l in range(max(k-1,0),min(k+2,10)):
                for m in range(max(l-1,0),min(l+2,10)):
                    for n in range(max(m-1,0),min(m+2,10)):
                        for o in range(max(n-1,0),min(n+2,10)):
                            for q in range(max(o-1,0),min(o+2,10)):
                                c += 1
                                if c == K:
                                    print((10000000*i+1000000*j+100000*k+10000*l+1000*m+100*n+10*o+q))

for i in range(1,10):
    for j in range(i-1,min(i+2,10)):
        for k in range(max(j-1,0),min(j+2,10)):
            for l in range(max(k-1,0),min(k+2,10)):
                for m in range(max(l-1,0),min(l+2,10)):
                    for n in range(max(m-1,0),min(m+2,10)):
                        for o in range(max(n-1,0),min(n+2,10)):
                            for q in range(max(o-1,0),min(o+2,10)):
                                for t in range(max(q-1,0),min(q+2,10)):
                                    c += 1
                                    if c == K:
                                        print((100000000*i+10000000*j+1000000*k+100000*l+10000*m+1000*n+100*o+10*q+t))

for i in range(1,10):
    for j in range(i-1,min(i+2,10)):
        for k in range(max(j-1,0),min(j+2,10)):
            for l in range(max(k-1,0),min(k+2,10)):
                for m in range(max(l-1,0),min(l+2,10)):
                    for n in range(max(m-1,0),min(m+2,10)):
                        for o in range(max(n-1,0),min(n+2,10)):
                            for q in range(max(o-1,0),min(o+2,10)):
                                for t in range(max(q-1,0),min(q+2,10)):
                                    for y in range(max(t-1,0),min(t+2,10)):
                                        c += 1
                                        if c == K:
                                            print((1000000000*i+100000000*j+10000000*k+1000000*l+100000*m+10000*n+1000*o+100*q+10*t+y))

# Optimized solution
import sys
from _collections import deque

K = int(eval(input()))
c = 9
A = [1,2,3,4,5,6,7,8,9]
q = deque(A)

if K <= 9:
    print(K)
else:
    while(True):
        a = q.popleft()
        if a % 10 == 0:
            c += 1
            if c == K:
                print((a*10))
                sys.exit()
            q.append(a*10)
            c += 1
            if c == K:
                print((a*10+1))
                sys.exit()
            q.append(a*10+1)
        elif a % 10 == 9:
            c += 1
            if c == K:
                print((a*10+9-1))
                sys.exit()
            q.append(a*10+9-1)
            c += 1
            if c == K:
                print((a*10+9))
                sys.exit()
            q.append(a*10+9)
        else:
            c += 1
            if c == K:
                print((a*10+a%10-1))
                sys.exit()
            q.append(a*10+a%10-1)
            c += 1
            if c == K:
                print((a*10+a%10))
                sys.exit()
            q.append(a*10+a%10)
            c += 1
            if c == K:
                print((a*10+a%10+1))
                sys.exit()
            q.append(a*10+a%10+1)