n = int(input()) li = [] a = "" x = 8 while x <= 100: while n >= x: a = str(n % x) + a n = n // x a = str(n % x) + a if a == "17": print(x) else: print("-1")