import sys
import math

Y = int(sys.stdin.readline().rstrip("\n"))
X = 0

factorials = []

for i in range(10):
    factorials.append(math.factorial(i))

def f(x):
    if 9 >= x >= 0:
        y = factorials[x]
    else:
        y = factorials[x % 10] + f(math.floor(x / 10))
    return y


while Y != f(X):
    X += 1
print(X)
