K = int(input()) def check(N): a = [1, 0, 0, 0, 1, 0, 1, 0, 2, 1] sz = len(str(N)) # dp_sub[上からi桁目まで見て][N未満かどうか][leadingzero中] = 通り数 dp_sub = [[[0, 0], [0, 0]] for _ in range(sz + 1)] # dp[上からi桁目まで見て][N未満かどうか][leadingzero中] = ○のsum dp = [[[0, 0], [0, 0]] for _ in range(sz + 1)] dp_sub[0][0][1] = 1 for i in range(sz): d = int(str(N)[i]) for isless in range(2): for islz in range(2): for num in range(10): if isless == 0 and num > d: continue isless2 = 1 if num < d else isless islz2 = 0 if num != 0 else islz dp_sub[i+1][isless2][islz2] += dp_sub[i][isless][islz] val = 0 if islz2 == 0: val += dp_sub[i][isless][islz] * a[num] dp[i+1][isless2][islz2] += dp[i][isless][islz] + val # print(i, dp[i], dp_sub[i]) # print(sz, dp[sz], dp_sub[sz]) ret = 0 for isless in range(2): ret += dp[sz][isless][0] return ret # print(check(K)) ok, ng = 10**18 + 1, 0 while ok - ng > 1: mid = (ok + ng) // 2 if check(mid) >= K: ok = mid else: ng = mid print(ok if check(ok) == K else -1)