import sys from itertools import product def count(a,id): n = len(a) #配列は末から dp=[[[0] * 20 for _ in range(2)] for _ in range(n+1)] dp[0][0][0] = 1 #条件に合わせてDP for i, less, cntd in product(range(n), range(2), range(19)): max_d = 9 if less else int(a[i]) for d in range(max_d+1): less_ = less or d < max_d cntd_ = cntd + (d==id) dp[i + 1][less_][cntd_] += dp[i][less][cntd] #合致するものを合算 ret = 0 for less, cntd in product((0,1), range(20)): ret += dp[n][less][cntd]*cntd return ret def countZero(a): n = len(a) #配列は末から dp=[[[[0] * 20 for _ in range(2)] for _ in range(2)] for _ in range(n+1)] dp[0][0][0][0] = 1 #条件に合わせてDP for i, less, leading0, cntZero in product(range(n), range(2), range(2), range(19)): max_d = 9 if less else int(a[i]) for d in range(max_d+1): less_ = less or d < max_d leading0_ = leading0 or d!=0 if leading0: cntZero_ = cntZero + (d==0) else: cntZero_ = 0 dp[i + 1][less_][leading0_][cntZero_] += dp[i][less][leading0][cntZero] #合致するものを合算 ret = 0 for less, cntZero_ in product((0,1), range(20)): ret += dp[n][less][1][cntZero_]*cntZero_ return ret def getK(N): N = str(N) ret = 0 for d in [4,6,8,8,9]: ret += count(N,d) ret += countZero(N) return ret #めぐる式二分探索 def is_ok(v): return getK(v) >= K def meguru_bisect(ng, ok): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok K = int(input()) N = meguru_bisect(0,10**18) if K!=getK(N): print(-1) else: print(N+1)