def check(s):
    chk = set(s)
    return len(chk)==len(s)

def func(k):
    ans = []
    for i in range(99999, 9999, -1):
        s = str(i)
        if(check(s)):
            ans.append(s)
    for i in range(9999, 999, -1):
        s = '0' + str(i)
        if(check(s)):
            ans.append(s)
    # 三位数的不用看了,因为补了2个0,不会是好数
    return ans

while True:
    try:
        k = int(input())
        result = func(k)
        print(result[k-1])
    except EOFError:
        break