K = int(input()) maru = [1,0,0,0,1,0,1,0,2,1,] s = sum(maru) t = s - 1 def calc(N): l = [] while N: l.append(N % 10) N //= 10 l = l[::-1] n = len(l) dp = [0] * n num = [0] * n for i in range(1,l[0]): dp[0] += maru[i] num[0] += 1 same = maru[l[0]] for i in range(1,n): dp[i] += dp[i-1] * 10 + num[i-1] * s num[i] += num[i-1] * 10 for j in range(l[i]): dp[i] += same + maru[j] num[i] += 1 dp[i] += t num[i] += 9 same += maru[l[i]] return dp[-1] + same import sys if K == 0: print(1) exit() start = 1 end = 10 ** 18 while end - start > 1: mid = end + start >> 1 if calc(mid) < K: start = mid else: end = mid if calc(end) == K: print(end) else: print(-1)