def solve():

    K = int(eval(input()))

    all = []

    for i in range(1,10):

        dfs(1,i,all)

    

    all.sort()

    print((all[K-1]))

    

def dfs(d, val, all):

    all.append(val)



    if d == 10:

        return

    

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

        add = val % 10 + j

        if 0 <= add <= 9:

            dfs(d+1, val*10+add, all)



if __name__ == '__main__':

    solve()
def solve():

    K = int(eval(input()))

    lunluns = []

    for i in range(1,10):

        dfs(1,i,lunluns)

    

    lunluns.sort()

    print((lunluns[K-1]))



def dfs(d,now,lunluns):

    lunluns.append(now)



    if d == 10:

        return

    

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

        add = now % 10 + i



        if 0 <= add <= 9:

            dfs(d+1,now*10+add, lunluns)

        

if __name__ == '__main__':

    solve()

def solve():
    K = int(eval(input()))
    all = []
    for i in range(1, 10):
        dfs(1, i, all)
    all.sort()
    print((all[K - 1]))


def dfs(d, val, all):
    all.append(val)
    if d == 10:
        return
    for j in [-1, 0, 1]:
        add = val % 10 + j
        if 0 <= add <= 9:
            dfs(d + 1, val * 10 + add, all)


if __name__ == "__main__":
    solve()

def solve():
    K = int(eval(input()))
    lunluns = []
    for i in range(1, 10):
        dfs(1, i, lunluns)
    lunluns.sort()
    print((lunluns[K - 1]))


def dfs(d, now, lunluns):
    lunluns.append(now)
    if d == 10:
        return
    for i in [-1, 0, 1]:
        add = now % 10 + i
        if 0 <= add <= 9:
            dfs(d + 1, now * 10 + add, lunluns)


if __name__ == "__main__":
    solve()

-    all = [] +    lunluns = [] -        dfs(1, i, all) -    all.sort() -    print((all[K - 1])) +        dfs(1, i, lunluns) +    lunluns.sort() +    print((lunluns[K - 1])) -def dfs(d, val, all): -    all.append(val) +def dfs(d, now, lunluns): +    lunluns.append(now) -    for j in [-1, 0, 1]: -        add = val % 10 + j +    for i in [-1, 0, 1]: +        add = now % 10 + i -            dfs(d + 1, val * 10 + add, all) +            dfs(d + 1, now * 10 + add, lunluns)