#n桁のるんるん数のrisutoを求める

import sys



sys.setrecursionlimit(10**9)



def runrun(n):

    if n == 1:

        return [['1','2','3','4','5','6','7','8','9']]

    else:

        li = runrun(n-1)

        li2 = []

        for i in range(len(li[n-2])):

            p = int(li[n-2][i][-1])

            if p == 0:

                li2.append(li[n-2][i]+'0')

                li2.append(li[n-2][i]+'1')

            elif p == 9:

                li2.append(li[n-2][i]+str(8))

                li2.append(li[n-2][i]+'9')

            else:

                li2.append(li[n-2][i]+str(p-1))

                li2.append(li[n-2][i]+str(p))

                li2.append(li[n-2][i]+str(p+1))

        li2 =[li2]

        li.extend(li2)

        return li

    





x = int(eval(input()))

t = True

k=1

b = 0

while t:

    a = runrun(k)

    b = 0

    #k桁までに何個るんるん数があるか数えるもの

    for i in range(len(a)):

        b+=(len(a[i]))

        #k桁ということが確定したあと以下の処理を行う

    if x <= b:

        t = False

        if k == 1:

            print(x)

        else:

            tmp = runrun(k-1)

            c = 0

#まずk-1桁までのるんるん数の数を数える

            for i in range(len(tmp)):

                c += (len(tmp[i]))

            s = a[k-1][x-c-1]

            print((int(s)))

    else:

        k += 1
#n桁のるんるん数のrisutoを求める

import sys



sys.setrecursionlimit(10**9)



from functools import lru_cache

@lru_cache(maxsize=None)



def runrun(n):

    if n == 1:

        return [['1','2','3','4','5','6','7','8','9']]

    else:

        li = runrun(n-1)

        li2 = []

        for i in range(len(li[n-2])):

            p = int(li[n-2][i][-1])

            if p == 0:

                li2.append(li[n-2][i]+'0')

                li2.append(li[n-2][i]+'1')

            elif p == 9:

                li2.append(li[n-2][i]+str(8))

                li2.append(li[n-2][i]+'9')

            else:

                li2.append(li[n-2][i]+str(p-1))

                li2.append(li[n-2][i]+str(p))

                li2.append(li[n-2][i]+str(p+1))

        li2 =[li2]

        li.extend(li2)

        return li

    





x = int(eval(input()))

t = True

k=1

b = 0

while t:

    a = runrun(k)

    b = 0

    #k桁までに何個るんるん数があるか数えるもの

    for i in range(len(a)):

        b+=(len(a[i]))

        #k桁ということが確定したあと以下の処理を行う

    if x <= b:

        t = False

        if k == 1:

            print(x)

        else:

            tmp = runrun(k-1)

            c = 0

#まずk-1桁までのるんるん数の数を数える

            for i in range(len(tmp)):

                c += (len(tmp[i]))

            s = a[k-1][x-c-1]

            print((int(s)))

    else:

        k += 1

# n桁のるんるん数のrisutoを求める
import sys

sys.setrecursionlimit(10**9)


def runrun(n):
    if n == 1:
        return [["1", "2", "3", "4", "5", "6", "7", "8", "9"]]
    else:
        li = runrun(n - 1)
        li2 = []
        for i in range(len(li[n - 2])):
            p = int(li[n - 2][i][-1])
            if p == 0:
                li2.append(li[n - 2][i] + "0")
                li2.append(li[n - 2][i] + "1")
            elif p == 9:
                li2.append(li[n - 2][i] + str(8))
                li2.append(li[n - 2][i] + "9")
            else:
                li2.append(li[n - 2][i] + str(p - 1))
                li2.append(li[n - 2][i] + str(p))
                li2.append(li[n - 2][i] + str(p + 1))
        li2 = [li2]
        li.extend(li2)
        return li


x = int(eval(input()))
t = True
k = 1
b = 0
while t:
    a = runrun(k)
    b = 0
    # k桁までに何個るんるん数があるか数えるもの
    for i in range(len(a)):
        b += len(a[i])
        # k桁ということが確定したあと以下の処理を行う
    if x <= b:
        t = False
        if k == 1:
            print(x)
        else:
            tmp = runrun(k - 1)
            c = 0
            # まずk-1桁までのるんるん数の数を数える
            for i in range(len(tmp)):
                c += len(tmp[i])
            s = a[k - 1][x - c - 1]
            print((int(s)))
    else:
        k += 1

# n桁のるんるん数のrisutoを求める
import sys

sys.setrecursionlimit(10**9)
from functools import lru_cache


@lru_cache(maxsize=None)
def runrun(n):
    if n == 1:
        return [["1", "2", "3", "4", "5", "6", "7", "8", "9"]]
    else:
        li = runrun(n - 1)
        li2 = []
        for i in range(len(li[n - 2])):
            p = int(li[n - 2][i][-1])
            if p == 0:
                li2.append(li[n - 2][i] + "0")
                li2.append(li[n - 2][i] + "1")
            elif p == 9:
                li2.append(li[n - 2][i] + str(8))
                li2.append(li[n - 2][i] + "9")
            else:
                li2.append(li[n - 2][i] + str(p - 1))
                li2.append(li[n - 2][i] + str(p))
                li2.append(li[n - 2][i] + str(p + 1))
        li2 = [li2]
        li.extend(li2)
        return li


x = int(eval(input()))
t = True
k = 1
b = 0
while t:
    a = runrun(k)
    b = 0
    # k桁までに何個るんるん数があるか数えるもの
    for i in range(len(a)):
        b += len(a[i])
        # k桁ということが確定したあと以下の処理を行う
    if x <= b:
        t = False
        if k == 1:
            print(x)
        else:
            tmp = runrun(k - 1)
            c = 0
            # まずk-1桁までのるんるん数の数を数える
            for i in range(len(tmp)):
                c += len(tmp[i])
            s = a[k - 1][x - c - 1]
            print((int(s)))
    else:
        k += 1

+from functools import lru_cache +@lru_cache(maxsize=None)