from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools

sys.setrecursionlimit(10**8)

mod = 10**9+7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))



x = inp()

for i in range(x,0,-1):

    for b in range(1,33):

        for p in range(2,11):

            if i == b**p:

                print(i)

                quit()
from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,fractions

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))



s = set()

for i in range(1,50):

    for j in range(2,10):

        if i**j > 1000:

            break

        s.add(i**j)

n = inp()

for i in range(n,0,-1):

    if i in s:

        print(i)

        break
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools

sys.setrecursionlimit(10**8)
mod = 10**9 + 7


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


def inpln(n):
    return list(int(sys.stdin.readline()) for i in range(n))


x = inp()
for i in range(x, 0, -1):
    for b in range(1, 33):
        for p in range(2, 11):
            if i == b**p:
                print(i)
                quit()

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


s = set()
for i in range(1, 50):
    for j in range(2, 10):
        if i**j > 1000:
            break
        s.add(i**j)
n = inp()
for i in range(n, 0, -1):
    if i in s:
        print(i)
        break

-import sys, bisect, math, itertools +import sys, bisect, math, itertools, fractions +INF = float("inf") -def inpln(n): -    return list(int(sys.stdin.readline()) for i in range(n)) - - -x = inp() -for i in range(x, 0, -1): -    for b in range(1, 33): -        for p in range(2, 11): -            if i == b**p: -                print(i) -                quit() +s = set() +for i in range(1, 50): +    for j in range(2, 10): +        if i**j > 1000: +            break +        s.add(i**j) +n = inp() +for i in range(n, 0, -1): +    if i in s: +        print(i) +        break