from sys import maxsize from collections import deque a = int(input()) n, m = 2, 1 while n**m < a: m += 1 q = deque() q.append((n, m)) visited = set() ans = maxsize if a == 5: ans = 5 while len(q) > 0: n, m = q.popleft() if n**m >= a and (n, m) not in visited: visited.add((n, m)) ans = min(ans, n * m) q.append((n + 1, m - 1)) q.append((n, m - 1)) q.append((n - 1, m)) print(ans)