k = int(eval(input()))

a = [1,2,3,4,5,6,7,8,9] #一桁目を入れる。

kosu = [0,1,1,1,1,1,1,1,1,1]

total = sum(kosu)

i = 0 #これが1桁に相当.

tempk = k*1

while k > total:

  b = a.copy() #aのコピーを作ってbを参照して新しいaを作る。

  tempk = k - total

  i += 1

  a = [] #ここでaをリセット

  kosub = kosu.copy() #各々の数で終わる個数を記録

  kosu = []

  for i in range(10):

    if i == 0:

      kosu.append(kosub[i]+kosub[i+1])

    elif i == 9:

      kosu.append(kosub[i-1]+kosub[i])

    else:

      kosu.append(kosub[i-1]+kosub[i]+kosub[i+1])

  total += sum(kosu)

  for i in range(len(b)):

    if b[i]%10 == 0:

      a.append(b[i]*10)

      a.append(b[i]*10+1)

    elif b[i]%10 == 9:

      a.append(b[i]*10+8)

      a.append(b[i]*10+9)

    else:

      a.append(b[i]*10+b[i]%10-1)

      a.append(b[i]*10+b[i]%10)      

      a.append(b[i]*10+b[i]%10+1)

  #print(a)

  #print(kosu)

  #print(total)

#print(tempk,total,len(a))

print((a[tempk-1]))
N = int(eval(input()))

if N <= 9:

  print(N)

  exit()

A = [[] for _ in range(11)]

A[0] = [1,2,3,4,5,6,7,8,9]

now = 9

keta = 1

while True:

  for x in A[keta-1]:

    x = str(x)

    last = int(x[-1])

    if last - 1 >= 0:

      temp = x+str(last-1)

      A[keta].append(int(temp))

      now += 1

      if now == N:

        print(temp)

        exit()

    temp = x+str(last)

    A[keta].append(int(temp))

    now += 1

    if now == N:

      print(temp)

      exit()

    if last+1 <= 9:

      temp = x+str(last+1)

      A[keta].append(int(temp))

      now += 1

      if now == N:

        print(temp)

        exit()

  keta += 1



k = int(eval(input()))
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]  # 一桁目を入れる。
kosu = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
total = sum(kosu)
i = 0  # これが1桁に相当.
tempk = k * 1
while k > total:
    b = a.copy()  # aのコピーを作ってbを参照して新しいaを作る。
    tempk = k - total
    i += 1
    a = []  # ここでaをリセット
    kosub = kosu.copy()  # 各々の数で終わる個数を記録
    kosu = []
    for i in range(10):
        if i == 0:
            kosu.append(kosub[i] + kosub[i + 1])
        elif i == 9:
            kosu.append(kosub[i - 1] + kosub[i])
        else:
            kosu.append(kosub[i - 1] + kosub[i] + kosub[i + 1])
    total += sum(kosu)
    for i in range(len(b)):
        if b[i] % 10 == 0:
            a.append(b[i] * 10)
            a.append(b[i] * 10 + 1)
        elif b[i] % 10 == 9:
            a.append(b[i] * 10 + 8)
            a.append(b[i] * 10 + 9)
        else:
            a.append(b[i] * 10 + b[i] % 10 - 1)
            a.append(b[i] * 10 + b[i] % 10)
            a.append(b[i] * 10 + b[i] % 10 + 1)
    # print(a)
    # print(kosu)
    # print(total)
# print(tempk,total,len(a))
print((a[tempk - 1]))

N = int(eval(input()))
if N <= 9:
    print(N)
    exit()
A = [[] for _ in range(11)]
A[0] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
now = 9
keta = 1
while True:
    for x in A[keta - 1]:
        x = str(x)
        last = int(x[-1])
        if last - 1 >= 0:
            temp = x + str(last - 1)
            A[keta].append(int(temp))
            now += 1
            if now == N:
                print(temp)
                exit()
        temp = x + str(last)
        A[keta].append(int(temp))
        now += 1
        if now == N:
            print(temp)
            exit()
        if last + 1 <= 9:
            temp = x + str(last + 1)
            A[keta].append(int(temp))
            now += 1
            if now == N:
                print(temp)
                exit()
    keta += 1

-k = int(eval(input())) -a = [1, 2, 3, 4, 5, 6, 7, 8, 9]  # 一桁目を入れる。 -kosu = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1] -total = sum(kosu) -i = 0  # これが1桁に相当. -tempk = k * 1 -while k > total: -    b = a.copy()  # aのコピーを作ってbを参照して新しいaを作る。 -    tempk = k - total -    i += 1 -    a = []  # ここでaをリセット -    kosub = kosu.copy()  # 各々の数で終わる個数を記録 -    kosu = [] -    for i in range(10): -        if i == 0: -            kosu.append(kosub[i] + kosub[i + 1]) -        elif i == 9: -            kosu.append(kosub[i - 1] + kosub[i]) -        else: -            kosu.append(kosub[i - 1] + kosub[i] + kosub[i + 1]) -    total += sum(kosu) -    for i in range(len(b)): -        if b[i] % 10 == 0: -            a.append(b[i] * 10) -            a.append(b[i] * 10 + 1) -        elif b[i] % 10 == 9: -            a.append(b[i] * 10 + 8) -            a.append(b[i] * 10 + 9) -        else: -            a.append(b[i] * 10 + b[i] % 10 - 1) -            a.append(b[i] * 10 + b[i] % 10) -            a.append(b[i] * 10 + b[i] % 10 + 1) -    # print(a) -    # print(kosu) -    # print(total) -# print(tempk,total,len(a)) -print((a[tempk - 1])) +N = int(eval(input())) +if N <= 9: +    print(N) +    exit() +A = [[] for _ in range(11)] +A[0] = [1, 2, 3, 4, 5, 6, 7, 8, 9] +now = 9 +keta = 1 +while True: +    for x in A[keta - 1]: +        x = str(x) +        last = int(x[-1]) +        if last - 1 >= 0: +            temp = x + str(last - 1) +            A[keta].append(int(temp)) +            now += 1 +            if now == N: +                print(temp) +                exit() +        temp = x + str(last) +        A[keta].append(int(temp)) +        now += 1 +        if now == N: +            print(temp) +            exit() +        if last + 1 <= 9: +            temp = x + str(last + 1) +            A[keta].append(int(temp)) +            now += 1 +            if now == N: +                print(temp) +                exit() +    keta += 1