import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict, Counter import string import random input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) pypyjit.set_param('max_unroll_recursion=-1') K = int(input()) circle = [1, 0, 0, 0, 1, 0, 1, 0, 2, 1] l = -1 r = 10 ** 18 while r - l > 1: c = (l + r) // 2 A = [int(c) for c in str(c)] dp = [[[0, 0] for _ in range(50)] for _ in range(len(A) + 1)] dp[0][0][0] = 1 for i in range((len(A))): for j in range(40): for k in range(10): n = circle[k] dp[i + 1][j + n][1] += dp[i][j][1] if k < A[i]: dp[i + 1][j + n][1] += dp[i][j][0] elif k == A[i]: dp[i + 1][j + n][0] += dp[i][j][0] acc = 0 for j in range(40): acc += j * sum(dp[len(A)][j]) acc -= len(A) for i in range(1, len(A)): acc -= (len(A) - i) * (pow(10, i) - pow(10, i - 1)) if acc == K: print(c) exit() elif acc > K: r = c else: l = c print(-1)