import sys
import math

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

factorials = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]

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)
