# -*- coding: utf-8 -*- import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll def comb(n, r): res = 1 for i in xrange(r): res *= n - i for i in xrange(1, r + 1): res /= i return res ans = 0 N = int(raw_input()) #3は5n個、5は3m個。1桁目は必ず5 for k in xrange(3, 26): s = 0 f = [] for i in xrange(3, k + 1, 3): j = k - i cnt = comb(j + i - 1, i - 1) s += cnt f.append(i) if N > s: N -= s else: tmp = [] for i in f: j = k - i for three in it.combinations(xrange(k - 1), j): num = ["5"] * k for l in three: num[l] = "3" tmp.append(int("".join(num))) tmp.sort() ans = tmp[N - 1] break if ans > 0: break print ans