def is_valid(num):

    if 1 <= num < 10:

        return True

    ns = list(map(int, str(num)))

    n = len(ns)

    for i in range(n - 1):

        if abs(ns[i] - ns[i + 1]) > 1:

            return False

    return True



lunluns = []

for i in range(1, 100000):

    if is_valid(i):

        lunluns.append(i)



d = {}



def dfs2(rem, pre):

    if rem == 0:

        return 1

    key = (rem, pre)

    if key in d:

        return d[key]



    res = 0

    if pre == -1:

        for i in range(10):

            res += dfs2(rem - 1, -1 if i == 0 else i)

    else:

        for i in range(10):

            if abs(i - pre) <= 1:

                res += dfs2(rem - 1, i)

    d[key] = res

    return res



assert dfs2(1, -1) == 10

assert dfs2(1, 1) == 3



def dfs(cur, n, k, pre, buf):

    if cur == n:

        return k == 1



    for i in range(10):

        if pre == -1 or abs(i - pre) <= 1:

            u = dfs2(n - cur - 1, -1 if pre == -1 and i == 0 else i)

            if u < k:

                k -= u

            else:

                buf.append(i)

                assert dfs(cur + 1, n, k, -1 if pre == -1 and i == 0 else i, buf)

                break

    return True



def solve(k):

    N = 500

    res = []

    assert dfs(0, N, k, -1, res)

    res = res[::-1]

    while res and res[-1] == 0:

        res.pop()

    if not res:

        res = [0]

    return ''.join(map(str, res[::-1]))



assert solve(3) == '2'

assert solve(1) == '0'

assert solve(2) == '1'

assert solve(4) == '3'



for i, num in enumerate(lunluns):

    assert solve(i + 2) == str(num)



if __name__ == '__main__':

    k = int(input())

    k += 1

    print(solve(k))

# 20/05/10 cost:20min



def is_valid(num):

    if 1 <= num < 10:

        return True

    ns = list(map(int, str(num)))

    n = len(ns)

    for i in range(n - 1):

        if abs(ns[i] - ns[i + 1]) > 1:

            return False

    return True



lunluns = []

for i in range(1, 10):

    if is_valid(i):

        lunluns.append(i)



d = {}



def dfs2(rem, pre, lt):

    if rem == 0:

        return 1

    key = (rem, pre, lt)

    if key in d:

        return d[key]



    res = 0

    if lt:

        for i in range(10):

            res += dfs2(rem - 1, i, lt and i == 0)

    else:

        for i in range(10):

            if abs(i - pre) <= 1:

                res += dfs2(rem - 1, i, False)

    d[key] = res

    return res



assert dfs2(1, -1, True) == 10

assert dfs2(1, 1, False) == 3



def dfs(cur, n, k, pre, lt, buf):

    if cur == n:

        return k == 1



    for i in range(10):

        if lt or abs(i - pre) <= 1:

            u = dfs2(n - cur - 1, i, lt and i == 0)

            if u < k:

                k -= u

            else:

                buf.append(i)

                assert dfs(cur + 1, n, k, i, lt and i == 0, buf)

                break

    return True



def solve(k):

    N = 500

    res = []

    assert dfs(0, N, k, -1, True, res)

    res = res[::-1]

    while res and res[-1] == 0:

        res.pop()

    if not res:

        res = [0]

    return ''.join(map(str, res[::-1]))



assert solve(3) == '2'

assert solve(1) == '0'

assert solve(2) == '1'

assert solve(4) == '3'



for i, num in enumerate(lunluns):

    assert solve(i + 2) == str(num)



if __name__ == '__main__':

    k = int(input())

    k += 1

    print(solve(k))

def is_valid(num):
    if 1 <= num < 10:
        return True
    ns = list(map(int, str(num)))
    n = len(ns)
    for i in range(n - 1):
        if abs(ns[i] - ns[i + 1]) > 1:
            return False
    return True


lunluns = []
for i in range(1, 100000):
    if is_valid(i):
        lunluns.append(i)
d = {}


def dfs2(rem, pre):
    if rem == 0:
        return 1
    key = (rem, pre)
    if key in d:
        return d[key]
    res = 0
    if pre == -1:
        for i in range(10):
            res += dfs2(rem - 1, -1 if i == 0 else i)
    else:
        for i in range(10):
            if abs(i - pre) <= 1:
                res += dfs2(rem - 1, i)
    d[key] = res
    return res


assert dfs2(1, -1) == 10
assert dfs2(1, 1) == 3


def dfs(cur, n, k, pre, buf):
    if cur == n:
        return k == 1
    for i in range(10):
        if pre == -1 or abs(i - pre) <= 1:
            u = dfs2(n - cur - 1, -1 if pre == -1 and i == 0 else i)
            if u < k:
                k -= u
            else:
                buf.append(i)
                assert dfs(cur + 1, n, k, -1 if pre == -1 and i == 0 else i, buf)
                break
    return True


def solve(k):
    N = 500
    res = []
    assert dfs(0, N, k, -1, res)
    res = res[::-1]
    while res and res[-1] == 0:
        res.pop()
    if not res:
        res = [0]
    return "".join(map(str, res[::-1]))


assert solve(3) == "2"
assert solve(1) == "0"
assert solve(2) == "1"
assert solve(4) == "3"
for i, num in enumerate(lunluns):
    assert solve(i + 2) == str(num)
if __name__ == "__main__":
    k = int(input())
    k += 1
    print(solve(k))

# 20/05/10 cost:20min
def is_valid(num):
    if 1 <= num < 10:
        return True
    ns = list(map(int, str(num)))
    n = len(ns)
    for i in range(n - 1):
        if abs(ns[i] - ns[i + 1]) > 1:
            return False
    return True


lunluns = []
for i in range(1, 10):
    if is_valid(i):
        lunluns.append(i)
d = {}


def dfs2(rem, pre, lt):
    if rem == 0:
        return 1
    key = (rem, pre, lt)
    if key in d:
        return d[key]
    res = 0
    if lt:
        for i in range(10):
            res += dfs2(rem - 1, i, lt and i == 0)
    else:
        for i in range(10):
            if abs(i - pre) <= 1:
                res += dfs2(rem - 1, i, False)
    d[key] = res
    return res


assert dfs2(1, -1, True) == 10
assert dfs2(1, 1, False) == 3


def dfs(cur, n, k, pre, lt, buf):
    if cur == n:
        return k == 1
    for i in range(10):
        if lt or abs(i - pre) <= 1:
            u = dfs2(n - cur - 1, i, lt and i == 0)
            if u < k:
                k -= u
            else:
                buf.append(i)
                assert dfs(cur + 1, n, k, i, lt and i == 0, buf)
                break
    return True


def solve(k):
    N = 500
    res = []
    assert dfs(0, N, k, -1, True, res)
    res = res[::-1]
    while res and res[-1] == 0:
        res.pop()
    if not res:
        res = [0]
    return "".join(map(str, res[::-1]))


assert solve(3) == "2"
assert solve(1) == "0"
assert solve(2) == "1"
assert solve(4) == "3"
for i, num in enumerate(lunluns):
    assert solve(i + 2) == str(num)
if __name__ == "__main__":
    k = int(input())
    k += 1
    print(solve(k))

+# 20/05/10 cost:20min -for i in range(1, 100000): +for i in range(1, 10): -def dfs2(rem, pre): +def dfs2(rem, pre, lt): -    key = (rem, pre) +    key = (rem, pre, lt) -    if pre == -1: +    if lt: -            res += dfs2(rem - 1, -1 if i == 0 else i) +            res += dfs2(rem - 1, i, lt and i == 0) -                res += dfs2(rem - 1, i) +                res += dfs2(rem - 1, i, False) -assert dfs2(1, -1) == 10 -assert dfs2(1, 1) == 3 +assert dfs2(1, -1, True) == 10 +assert dfs2(1, 1, False) == 3 -def dfs(cur, n, k, pre, buf): +def dfs(cur, n, k, pre, lt, buf): -        if pre == -1 or abs(i - pre) <= 1: -            u = dfs2(n - cur - 1, -1 if pre == -1 and i == 0 else i) +        if lt or abs(i - pre) <= 1: +            u = dfs2(n - cur - 1, i, lt and i == 0) -                assert dfs(cur + 1, n, k, -1 if pre == -1 and i == 0 else i, buf) +                assert dfs(cur + 1, n, k, i, lt and i == 0, buf) -    assert dfs(0, N, k, -1, res) +    assert dfs(0, N, k, -1, True, res)