from functools import lru_cache def General_Binary_Decrease_Search_Integer(L, R, cond, default=None): """ 条件式が単調減少であるとき, 整数上で二部探索を行う. L: 解の下限 R: 解の上限 cond: 条件 (1変数関数, 広義単調減少 を満たす) default: R で条件を満たさないときの返り値 """ if not(cond(L)): return default if cond(R): return R L-=1 while R-L>1: C=L+(R-L)//2 if cond(C): L=C else: R=C return L @lru_cache(maxsize=None) def count(N): if N<10: Ans=0 for n in range(1,N+1): Ans+=A[n] return Ans q,r=divmod(N,10) x=y=0 for i in range(10): if i<=r: x+=A[i] else: y+=A[i] return count(q)*(r+1)+x*(q+1)-1+count(q-1)*(9-r)+y*q #================================================== A=[1,0,0,0,1,0,1,0,2,1] K=int(input()) N=General_Binary_Decrease_Search_Integer(0,10**18,lambda x:count(x)<=K) print(N if count(N)==K else -1)