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



def dps(curr_num):

    end_num = curr_num[-1]

    for i in [-1,0,1]:

        added_num = int(end_num) + i

        if added_num == -1 or added_num == 10:

            continue

        curr_num_plus = curr_num + str(added_num)

        ln_l.append(int(curr_num_plus))

        if len(curr_num_plus) < 10:

            dps(curr_num_plus)



def main():

    k = int(eval(input()))

    for i in range(1,9+1):

        dps(str(i))

    ln_l.sort()

    print((ln_l[k-1]))



if __name__ == "__main__":

    main()
def dfs(lls, curr_num, lim):

    if curr_num > lim: return

    lls.append(curr_num)

    last_num = int(str(curr_num)[-1])

    if last_num > 0:

        dfs(lls, curr_num*10+last_num-1, lim)

    if last_num < 9:

        dfs(lls, curr_num*10+last_num+1, lim)

    dfs(lls, curr_num*10+last_num, lim)





def main():

    k = int(eval(input()))

    lls = []

    for i in range(1,10):

        dfs(lls, i, 3234566668)



    lls.sort()

    print((lls[k-1]))

    





if __name__ == "__main__":

    main()
ln_l = [1, 2, 3, 4, 5, 6, 7, 8, 9]


def dps(curr_num):
    end_num = curr_num[-1]
    for i in [-1, 0, 1]:
        added_num = int(end_num) + i
        if added_num == -1 or added_num == 10:
            continue
        curr_num_plus = curr_num + str(added_num)
        ln_l.append(int(curr_num_plus))
        if len(curr_num_plus) < 10:
            dps(curr_num_plus)


def main():
    k = int(eval(input()))
    for i in range(1, 9 + 1):
        dps(str(i))
    ln_l.sort()
    print((ln_l[k - 1]))


if __name__ == "__main__":
    main()

def dfs(lls, curr_num, lim):
    if curr_num > lim:
        return
    lls.append(curr_num)
    last_num = int(str(curr_num)[-1])
    if last_num > 0:
        dfs(lls, curr_num * 10 + last_num - 1, lim)
    if last_num < 9:
        dfs(lls, curr_num * 10 + last_num + 1, lim)
    dfs(lls, curr_num * 10 + last_num, lim)


def main():
    k = int(eval(input()))
    lls = []
    for i in range(1, 10):
        dfs(lls, i, 3234566668)
    lls.sort()
    print((lls[k - 1]))


if __name__ == "__main__":
    main()

-ln_l = [1, 2, 3, 4, 5, 6, 7, 8, 9] - - -def dps(curr_num): -    end_num = curr_num[-1] -    for i in [-1, 0, 1]: -        added_num = int(end_num) + i -        if added_num == -1 or added_num == 10: -            continue -        curr_num_plus = curr_num + str(added_num) -        ln_l.append(int(curr_num_plus)) -        if len(curr_num_plus) < 10: -            dps(curr_num_plus) +def dfs(lls, curr_num, lim): +    if curr_num > lim: +        return +    lls.append(curr_num) +    last_num = int(str(curr_num)[-1]) +    if last_num > 0: +        dfs(lls, curr_num * 10 + last_num - 1, lim) +    if last_num < 9: +        dfs(lls, curr_num * 10 + last_num + 1, lim) +    dfs(lls, curr_num * 10 + last_num, lim) -    for i in range(1, 9 + 1): -        dps(str(i)) -    ln_l.sort() -    print((ln_l[k - 1])) +    lls = [] +    for i in range(1, 10): +        dfs(lls, i, 3234566668) +    lls.sort() +    print((lls[k - 1]))