import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) def Base_10_to_n(x, n): if int(x / n): return Base_10_to_n(int(x / n), n) + str(x % n) return str(x % n) a = int(readline()) for x in range(2, 10 ** 4): if Base_10_to_n(a, x) == '17': print(x) break else: print(-1)