CodeEff/ECCO huggingface dataset:
# Original solution
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(K: int):

    X = set()

    def rec(keta, val):
        X.add(val)
        if keta == 10:
            return

        for j in range(-1, 2):
            add = (val % 10)+j
            if add >= 0 and add <= 9:
                rec(keta+1, val*10+add)

    for i in range(1, 10):
        rec(1, i)
    X = sorted(X)
    print((X[K-1]))

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)


if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys
from collections import deque
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(K: int):

    h = deque([])

    for i in range(1, 10):
        h.append(i)

    for i in range(K-1):
        s = h.popleft()
        for j in range(-1, 2):
            add = (s % 10)+j
            if 0 <= add <= 9:
                h.append(s*10+add)
    print((h.popleft()))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)


if __name__ == '__main__':
    main()
# Original solution
K=int(eval(input()))

from collections import deque

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

k=1
while True:
    a=d.popleft()
    if k==K:
        print(a)
        exit()
    else:
        k+=1
    r=a%10
    if r==0:
        for i in [0,1]:
            temp=a*10+i
            d.append(temp)
    elif r==9:
        for i in [8,9]:
            temp=a*10+i
            d.append(temp)
    else:
        for i in [-1,0,1]:
            temp=a*10+(r+i)
            d.append(temp)


# Optimized solution
K=int(eval(input()))

from collections import deque

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

k=1
while True:
    a=d.popleft()
    if k==K:
        print(a)
        exit()
    else:
        k+=1
    r=a%10
    if 0<r<=9:
        temp = a * 10 + (r -1)
        d.append(temp)
    temp=a*10+r
    d.append(temp)
    if 0<=r<9:
        temp=a*10+(r+1)
        d.append(temp)
# Original solution
def d_lunlun_number():
    import sys
    sys.setrecursionlimit(10**6)
    K = int(eval(input()))

    ans = []

    def dfs(num, current, digit_max):
        if current == digit_max:
            ans.append(num)
            return None
        for n in range(10):
            if abs((num % 10) - n) >= 2:
                continue
            dfs(num * 10 + n, current + 1, digit_max)

    for leading in range(1, 10):
        for d in range(1, 11):
            dfs(leading, 1, d)
    return sorted(ans)[K - 1]

print((d_lunlun_number()))

# Optimized solution
def d_lunlun_number():
    from collections import deque
    K = int(eval(input()))

    queue = deque(list(range(1, 10)))
    ans = -1
    for _ in range(K):
        ans = queue.popleft()
        lsd = ans % 10  # least significant digit
        if lsd != 0:
            queue.append(10 * ans + (lsd - 1))
        queue.append(10 * ans + lsd)
        if ans % 10 != 9:
            queue.append(10 * ans + (lsd + 1))
    return ans

print((d_lunlun_number()))
# Original solution
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))

k = ni()

LIMIT = 12
luns = []


def make_lunlun(l):
    if len(l) == LIMIT:
        return
    luns.append(int(''.join(list(map(str,l)))))

    if l[-1]!=0:
        make_lunlun(l+[(l[-1]-1)%10])
    make_lunlun(l+[(l[-1])%10])
    if l[-1]!=9:
        make_lunlun(l+[(l[-1]+1)%10])


for i in range(1,10):
    make_lunlun([i])

print((sorted(luns)[k-1]))

# Optimized solution
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))

k = ni()

luns = []


def make_lunlun(l):
    if l > 3234566667:
        return
    luns.append(l)

    last = l-l//10*10

    if last!=0:
        make_lunlun(l*10 + last-1)
    make_lunlun(l*10+last)
    if last!=9:
        make_lunlun(l*10 + last+1)


for i in range(1,10):
    make_lunlun(i)

print((sorted(luns)[k-1]))
# Original solution
k=int(eval(input()))
cur=1
ans=[]
while len(ans)<k:
    num=str(cur)
    n=len(num)
    flag=True
    pos=-1
  #  print(num,end=' num\n')
    for i in range(n-1):
        if abs(int(num[i])-int(num[i+1]))>1:
            pos=i+1
            flag=False
            break
 #   print(flag)
    if flag==True:
        ans.append(cur)
        cur+=1
    else:
        if int(num[pos])!=9:
            ch=str(int(num[pos])+1)
#            print(ch)
            cur=int(num[:pos]+ch+num[pos+1:])
        else:
            ch=str(int(num[pos-1])+1)
            cur=int(num[:pos-1]+ch+'0'*len(num[pos:]))
print((ans[-1]))


# Optimized solution
k=int(eval(input()))
cur=1
ans=-1
cnt=0
while cnt<k:
    num=str(cur)
    n=len(num)
    flag=True
    pos=-1
  #  print(num,end=' num\n')
    for i in range(n-1):
        if abs(int(num[i])-int(num[i+1]))>1:
            pos=i+1
            flag=False
            break
 #   print(flag)
    if flag==True:
        ans=cur
        cur+=1
        cnt+=1
    else:
        if int(num[pos])!=9:
            ch=str(int(num[pos])+1)
#            print(ch)
            cur=int(num[:pos]+ch+num[pos+1:])
        else:
            ch=str(int(num[pos-1])+1)
            cur=int(num[:pos-1]+ch+'0'*len(num[pos:]))
print(ans)
# Original solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())

    n = 0

    def dfs(vec, d):
        nonlocal n
        if d == 0:
            n += 1
            if n == K:
                print((''.join(map(str, vec))))
                return
            else:
                return

        for i in range(max(0, vec[-1] - 1), min(9, vec[-1] + 1) + 1):
            vec.append(i)
            dfs(vec, d - 1)
            if n >= K:
                return
            vec.pop()

    for d in range(10 ** 20):
        for i in range(1, 10):
            vec = [i]
            dfs(vec, d)
            if n >= K:
                return

    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())

    queue = deque(list(range(1, 10)))
    for _ in range(K):
        n = queue.popleft()

        tail = n % 10
        n10 = n * 10
        if tail != 0:
            queue.append(n10 + tail - 1)
        queue.append(n10 + tail)
        if tail != 9:
            queue.append(n10 + tail + 1)

    print(n)
    return


if __name__ == '__main__':
    main()
# Original solution
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())

    queue = deque(list(range(1, 10)))
    for _ in range(K):
        n = queue.popleft()

        tail = n % 10
        n10 = n * 10
        if tail != 0:
            queue.append(n10 + tail - 1)
        queue.append(n10 + tail)
        if tail != 9:
            queue.append(n10 + tail + 1)

    print(n)
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())

    queue = deque(list(range(1, 10)))
    for _ in range(K):
        n = queue.popleft()

        tail = n % 10
        n10 = n * 10
        if tail == 0:
            queue.append(n10 + tail)
            queue.append(n10 + tail + 1)
        elif tail == 9:
            queue.append(n10 + tail - 1)
            queue.append(n10 + tail)
        else:
            queue.append(n10 + tail - 1)
            queue.append(n10 + tail)
            queue.append(n10 + tail + 1)

    print(n)
    return


if __name__ == '__main__':
    main()
# Original solution
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())

    queue = deque(list(range(1, 10)))
    for _ in range(K):
        n = queue.popleft()

        tail = n % 10
        n10 = n * 10
        if tail == 0:
            queue.append(n10 + tail)
            queue.append(n10 + tail + 1)
        elif tail == 9:
            queue.append(n10 + tail - 1)
            queue.append(n10 + tail)
        else:
            queue.append(n10 + tail - 1)
            queue.append(n10 + tail)
            queue.append(n10 + tail + 1)

    print(n)
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())

    vec = list(range(1, 10))
    for i in range(K):
        tail = vec[i] % 10
        n10 = vec[i] * 10
        if tail == 0:
            vec.append(n10 + tail)
            vec.append(n10 + tail + 1)
        elif tail == 9:
            vec.append(n10 + tail - 1)
            vec.append(n10 + tail)
        else:
            vec.append(n10 + tail - 1)
            vec.append(n10 + tail)
            vec.append(n10 + tail + 1)

    print((vec[K - 1]))
    return


if __name__ == '__main__':
    main()
# Original solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())

    vec = list(range(1, 10))
    for i in range(K):
        tail = vec[i] % 10
        n10 = vec[i] * 10
        if tail == 0:
            vec.append(n10 + tail)
            vec.append(n10 + tail + 1)
        elif tail == 9:
            vec.append(n10 + tail - 1)
            vec.append(n10 + tail)
        else:
            vec.append(n10 + tail - 1)
            vec.append(n10 + tail)
            vec.append(n10 + tail + 1)

    print((vec[K - 1]))
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())

    vec = list(range(1, 10))
    for i in range(K):
        tail = vec[i] % 10
        n10 = vec[i] * 10
        if tail == 0:
            vec.append(n10 + tail)
            vec.append(n10 + tail + 1)
        elif tail == 9:
            vec.append(n10 + tail - 1)
            vec.append(n10 + tail)
        else:
            vec.append(n10 + tail - 1)
            vec.append(n10 + tail)
            vec.append(n10 + tail + 1)
            
        if len(vec) == K:
            break

    print((vec[K - 1]))
    return


if __name__ == '__main__':
    main()
# Original solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())

    vec = list(range(1, 10))
    for i in range(K):
        tail = vec[i] % 10
        if tail == 0:
            vec.append(vec[i] * 10 + tail)
            vec.append(vec[i] * 10 + tail + 1)
        elif tail == 9:
            vec.append(vec[i] * 10 + tail - 1)
            vec.append(vec[i] * 10 + tail)
        else:
            vec.append(vec[i] * 10 + tail - 1)
            vec.append(vec[i] * 10 + tail)
            vec.append(vec[i] * 10 + tail + 1)

        if len(vec) == K:
            break

    print((vec[K - 1]))
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())

    vec = list(range(1, 10))
    for i in range(K):
        tail = vec[i] % 10
        n10 = vec[i] * 10
        if tail == 0:
            vec.append(n10 + tail)
            vec.append(n10 + tail + 1)
        elif tail == 9:
            vec.append(n10 + tail - 1)
            vec.append(n10 + tail)
        else:
            vec.append(n10 + tail - 1)
            vec.append(n10 + tail)
            vec.append(n10 + tail + 1)

        if len(vec) >= K:
            break

    print((vec[K - 1]))
    return


if __name__ == '__main__':
    main()
# Original solution
k = int(eval(input()))

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

while k:
    if k <= len(A):
        print((A[k-1]))
        exit()

    k -= len(A)
    
    old = []
    old, A = A, old
    for x in old:
        for i in range(-1, 2):
          d = (x % 10) + i
          if d < 0 or d > 9: continue
            
          nx = (x * 10) + d
          A.append(nx)

# Optimized solution
k = int(eval(input()))

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

while True:
    if k <= len(RunRun):
        print((RunRun[k-1]))
        exit()
        
    k -= len(RunRun)
    
    now = []
    now, RunRun = RunRun, now

    for r in now:
        for i in range(-1, 2):
            tmp = r % 10 + i
            if tmp < 0 or 9 < tmp: continue
            tmp = (r * 10) + tmp
            RunRun.append(tmp)
        #print(RunRun)
# Original solution
from collections import deque
K = int(eval(input()))

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

while K:
    if K == 1:
        ans = que.popleft()
        break
    K -= 1
    v = que.popleft()
    if v[-1] == '0':
        que.append(v + '0')
        que.append(v + '1')
    elif v[-1] == '9':
        que.append(v + '8')
        que.append(v + '9')
    else:
        que.append(v + str(int(v[-1]) - 1))
        que.append(v + str(int(v[-1])))
        que.append(v + str(int(v[-1]) + 1))

print(ans)

# Optimized solution
from collections import deque


def main():
    K = int(eval(input()))
    que = deque(['1', '2', '3', '4', '5', '6', '7', '8', '9'])

    while K:
        if K == 1:
            ans = que.popleft()
            break
        K -= 1
        v = que.popleft()
        if v[-1] == '0':
            que.append(v + '0')
            que.append(v + '1')
        elif v[-1] == '9':
            que.append(v + '8')
            que.append(v + '9')
        else:
            que.append(v + str(int(v[-1]) - 1))
            que.append(v + str(int(v[-1])))
            que.append(v + str(int(v[-1]) + 1))

    print(ans)

if __name__ == '__main__':
    main()
# Original solution
from collections import deque


def main():
    K = int(eval(input()))
    que = deque(['1', '2', '3', '4', '5', '6', '7', '8', '9'])

    while K:
        if K == 1:
            ans = que.popleft()
            break
        K -= 1
        v = que.popleft()
        if v[-1] == '0':
            que.append(v + '0')
            que.append(v + '1')
        elif v[-1] == '9':
            que.append(v + '8')
            que.append(v + '9')
        else:
            que.append(v + str(int(v[-1]) - 1))
            que.append(v + str(int(v[-1])))
            que.append(v + str(int(v[-1]) + 1))

    print(ans)

if __name__ == '__main__':
    main()

# Optimized solution
from collections import deque

def main():
    K = int(eval(input()))
    que = deque([i for i in range(1, 10)])

    while K:
        if K == 1:
            ans = que.popleft()
            break
        K -= 1
        v = que.popleft()
        if v % 10 == 0:
            que.append(v * 10)
            que.append(v * 10 + 1)
        elif v % 10 == 9:
            que.append(v * 10 + 8)
            que.append(v * 10 + 9)
        else:
            que.append(v * 10 + (v % 10 - 1))
            que.append(v * 10 + (v % 10))
            que.append(v * 10 + (v % 10 + 1))
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
def dfs(s):
    d=len(s)
    if d>10:
        return
    
    if s!='':
        if s[0]!='0':
            num.add(int(s))

    for c in '0123456789':
        if s=='':
            dfs(s+c)
        else:
            if abs(int(s[-1])-int(c))<=1:
                dfs(s+c)

k=int(eval(input()))
num=set()

dfs('')
ans=list(num)
ans.sort()
print((ans[k-1]))

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

ans=0
cnt=0

while 1:
    x=q.popleft()
    cnt+=1
    if cnt==k:
        ans=x
        break
    xmod10 = x % 10
    if xmod10 != 0:
        q.append(10*x+(xmod10-1))
    q.append(10*x+(xmod10))
    if xmod10 != 9:
        q.append(10*x+(xmod10+1))

print(ans)
# Original solution
def dfs(s,l):
  if s!="":
    if len(s)>10 or s[0]=="0":
      return
  if s!="":
    l.append(int(s))
  for c in "0123456789":
    if s!="":
      if abs(int(s[-1])-int(c))<=1:
        dfs(s+c,l)
    else:
      if c!="0":
        dfs(s+c,l)

k=int(eval(input()))
l=[]
dfs("",l)
l.sort()
print((l[k-1]))


# Optimized solution
import sys
sys.setrecursionlimit(10000000)
def dfs(s):
  if len(s)==11:
    return
  if s!="":
    a.append(int(s))
  for c in "0123456789":
    if s=="" and c=="0":continue
    if len(s)>0:
      if abs(ord(s[-1])-ord(c))<=1:
        dfs(s+c)
    else:
        dfs(s+c)
k=int(eval(input()))
a=[]
dfs("")
a=list(set(a))
a.sort()
print((a[k-1]))
# Original solution
import sys
sys.setrecursionlimit(10000000)
def dfs(s):
  if len(s)==11:
    return
  if s!="":
    a.append(int(s))
  for c in "0123456789":
    if s=="" and c=="0":continue
    if len(s)>0:
      if abs(ord(s[-1])-ord(c))<=1:
        dfs(s+c)
    else:
        dfs(s+c)
k=int(eval(input()))
a=[]
dfs("")
a=list(set(a))
a.sort()
print((a[k-1]))


# Optimized solution
import sys
sys.setrecursionlimit(10000000)
def dfs(s):
  if len(s)==11:
    return
  if s!="":
    a.append(int(s))
  for c in "0123456789":
    if s=="" and c=="0":continue
    if s!="":
      if abs(ord(c)-ord(s[-1]))<=1:
        dfs(s+c)
    else:
      dfs(s+c)

k=int(eval(input()))
a=[]
dfs("")
a=list(set(a))
a.sort()
print((a[k-1]))
# Original solution
import collections
k = int(eval(input()))
n = 10**10

li = list(range(1,10))
num_li = li[:]
q = collections.deque(li)
count = 0

for i in range(1,n):
    num = str(q.popleft())
    go = int(num[-1])
    if go != 0:
        numa = num + str(go - 1)
        num_li.append(int(numa))
        q.append(int(numa))
        count += 1
    numa = num + str(go)
    num_li.append(int(numa))
    q.append(int(numa))
    count += 1
    if go != 9:
        numa = num + str(go + 1)
        num_li.append(int(numa))
        q.append(int(numa))
        count += 1

    if count > k+1:
        break

print((num_li[k-1]))

# Optimized solution
import collections

k = int(eval(input()))

li = [str(i) for i in range(1,10)]
st_li = li[:]
q = collections.deque(li)
count = 0
n = 10 ** 10

for i in range(1, n):
    a = q.popleft()
    num = int(a[-1])
    if num != 0:
        aa = a + str(num-1)
        st_li.append(aa)
        q.append(aa)
        count += 1
    aa = a + str(num)
    st_li.append(aa)
    q.append(aa)
    count += 1
    if num != 9:
        aa = a + str(num+1)
        st_li.append(aa)
        q.append(aa)
        count += 1
    if count > k+1:
        print((st_li[k - 1]))
        exit(0)
# Original solution
import sys
from collections import deque


def input():
    return sys.stdin.readline().strip()


def main():
    K = int(eval(input()))
    ans = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
    for _ in range(K - 1):
        a = ans.popleft()
        if a % 10 == 0:
            ans.append(a * 10)
            ans.append(a * 10 + 1)
        elif a % 10 == 9:
            ans.append(a * 10 + 8)
            ans.append(a * 10 + 9)
        else:
            w = a % 10
            ans.append(a * 10 + w - 1)
            ans.append(a * 10 + w)
            ans.append(a * 10 + w + 1)
    print((ans.popleft()))


if __name__ == "__main__":
    main()


# Optimized solution
import sys
from collections import deque


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    K = int(eval(input()))
    q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
    for i in range(K):
        d = q.popleft()
        a = d % 10
        if a == 0:
            q.append(d * 10)
            q.append(d * 10 + 1)
        elif a == 9:
            q.append(d * 10 + a - 1)
            q.append(d * 10 + a)
        else:
            q.append(d * 10 + a - 1)
            q.append(d * 10 + a)
            q.append(d * 10 + a + 1)
    print(d)


if __name__ == "__main__":
    main()
# Original solution
k=int(eval(input()))
L=[]
def f(d,now,L):
  L.append(now)
  
  if d==10:
    return
  
  for j in range(-1,2):
    v=now%10+j
    if 0<=v<=9:
      f(d+1,now*10+v,L)

for l in range(1,10):
  f(1,l,L)
L.sort()
print((L[k-1]))

      

# Optimized solution
from collections import deque

k=int(eval(input()))

lunlun=deque(i for i in range(1,10))
for _ in range(k-1):
  p=lunlun.popleft()
  if p%10!=0:
    lunlun.append(10*p+p%10-1)
  lunlun.append(10*p+p%10)
  if p%10!=9:
    lunlun.append(10*p+p%10+1)
print((lunlun.popleft()))
# Original solution
from sys import stdin,setrecursionlimit
k = int(stdin.readline().rstrip())
li = [i for i in range(1,10)]
#ルンルン最初の数
def runrun(before,kazu):
    if before == 0:
        li.append(int(kazu+str(before+1)))
        li.append(int(kazu+str(before)))
    elif before == 9:
        li.append(int(kazu+str(before-1)))
        li.append(int(kazu+str(before)))
    else:
        li.append(int(kazu+str(before+1)))
        li.append(int(kazu+str(before-1)))
        li.append(int(kazu+str(before)))
    if len(kazu)+1 >= 10:
        return
    else:
        if before == 0:
            return runrun(before+1,kazu+str(before+1)),runrun(before,kazu+str(before))
        elif before == 9:
            return runrun(before-1,kazu+str(before-1)),runrun(before,kazu+str(before))
        else:
            return runrun(before+1,kazu+str(before+1)),runrun(before-1,kazu+str(before-1)),runrun(before,kazu+str(before))
for i in range(1,10):
    runrun(i,str(i))
li.sort()
print((li[k-1]))

# Optimized solution
from queue import deque

k = int(eval(input()))
que = deque()
for i in range(1,10):
    que.append(i)

for i in range(k):
    if i == (k-1):
        print((que.popleft()))
        exit()
    now = que.popleft()
    if now%10 != 0:
        que.append(now*10+now%10-1)
    que.append(now*10+now%10)
    if now%10 != 9:
        que.append(now*10+now%10+1)
# Original solution
k=int(eval(input()))
ans=[[i for i in range(1,10)]]
d=9
while d<k:
    ans.append([])
    for i in ans[-2]:
        x=str(i)
        y=int(x[0])
        if y==1:
            ans[-1].append(str(y)+x)
            ans[-1].append(str(y+1)+x)
        elif 2<=y<=8:
            ans[-1].append(str(y-1)+x)
            ans[-1].append(str(y)+x)
            ans[-1].append(str(y+1)+x)
        else:
            ans[-1].append(str(y-1)+x)
            ans[-1].append(str(y)+x)
        z=int(x[-1])
        if z==0:
            ans[-1].append(x+str(z))
            ans[-1].append(x+str(z+1))
        elif 1<=z<=8:
            ans[-1].append(x+str(z-1))
            ans[-1].append(x+str(z))
            ans[-1].append(x+str(z+1))
        else:
            ans[-1].append(x+str(z-1))
            ans[-1].append(x+str(z))
    ans[-1]=list(set(ans[-1]))
    d+=len(ans[-1])
l=len(ans[-1])
v=sorted([int(i) for i in ans[-1]])

print((v[k-(d-l)-1]))

# Optimized solution
k=int(eval(input()))
ans=[[i for i in range(1,10)]]
d=9
while d<k:
    ans.append([])
    for i in ans[-2]:
        x=str(i)
        z=int(x[-1])
        if z==0:
            ans[-1].append(x+str(z))
            ans[-1].append(x+str(z+1))
        elif 1<=z<=8:
            ans[-1].append(x+str(z-1))
            ans[-1].append(x+str(z))
            ans[-1].append(x+str(z+1))
        else:
            ans[-1].append(x+str(z-1))
            ans[-1].append(x+str(z))
    d+=len(ans[-1])
l=len(ans[-1])
v=sorted([int(i) for i in ans[-1]])

print((v[k-(d-l)-1]))