import math a = int(input()) ans = a for i in [2, 3, 5, 7]: res = int(math.ceil(math.log(a, i))) ans = min(ans, i * res) print(ans)