from collections import * def calc(x): x = str(x) l = len(x) dp1 = [[[0]*2 for _ in range(2)] for _ in range(l+1)] dp1[0][0][0] = 1 dp2 = [[[0]*2 for _ in range(2)] for _ in range(l+1)] for i in range(l): d = int(x[i]) for j in range(2): for k in range(2): for n in range(10 if k else d+1): add = j if n==0 else cnt[n] dp1[i+1][j|(n>0)][k|(n0)][k|(n=K: r = m-1 else: l = m+1 return l K = int(input()) cnt = defaultdict(int) cnt[4] = 1 cnt[6] = 1 cnt[8] = 2 cnt[9] = 1 x = binary_search() if calc(x)==K: print(x) else: print(-1)