def is_perfect_power(n):

    if n == 1:

        return True

    div = 2

    divs = []

    while n != 1:

        if n % div == 0:

            n //= div

            divs.append(div)

        else:

            div += 1

    divs_d = {d: 0 for d in set(divs)}

    for d in divs:

        divs_d[d] += 1

    divs_s = {n for n in list(divs_d.values())}

    if min(divs_s) > 1:

        for d in divs_s:

            if d % min(divs_s) != 0:

                return False

    else:

        return False

    return True





X = int(eval(input()))

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

    if is_perfect_power(x):

        print(x)

        break

def is_perfect_power(n):

    return n in {

        1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64, 81, 100, 121, 125, 128, 144,

        169, 196, 216, 225, 243, 256, 289, 324, 343, 361, 400, 441, 484, 512,

        529, 576, 625, 676, 729, 784, 841, 900, 961, 1000

    }





X = int(eval(input()))

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

    if is_perfect_power(x):

        print(x)

        break

def is_perfect_power(n):
    if n == 1:
        return True
    div = 2
    divs = []
    while n != 1:
        if n % div == 0:
            n //= div
            divs.append(div)
        else:
            div += 1
    divs_d = {d: 0 for d in set(divs)}
    for d in divs:
        divs_d[d] += 1
    divs_s = {n for n in list(divs_d.values())}
    if min(divs_s) > 1:
        for d in divs_s:
            if d % min(divs_s) != 0:
                return False
    else:
        return False
    return True


X = int(eval(input()))
for x in range(X, 0, -1):
    if is_perfect_power(x):
        print(x)
        break

def is_perfect_power(n):
    return n in {
        1,
        4,
        8,
        9,
        16,
        25,
        27,
        32,
        36,
        49,
        64,
        81,
        100,
        121,
        125,
        128,
        144,
        169,
        196,
        216,
        225,
        243,
        256,
        289,
        324,
        343,
        361,
        400,
        441,
        484,
        512,
        529,
        576,
        625,
        676,
        729,
        784,
        841,
        900,
        961,
        1000,
    }


X = int(eval(input()))
for x in range(X, 0, -1):
    if is_perfect_power(x):
        print(x)
        break

-    if n == 1: -        return True -    div = 2 -    divs = [] -    while n != 1: -        if n % div == 0: -            n //= div -            divs.append(div) -        else: -            div += 1 -    divs_d = {d: 0 for d in set(divs)} -    for d in divs: -        divs_d[d] += 1 -    divs_s = {n for n in list(divs_d.values())} -    if min(divs_s) > 1: -        for d in divs_s: -            if d % min(divs_s) != 0: -                return False -    else: -        return False -    return True +    return n in { +        1, +        4, +        8, +        9, +        16, +        25, +        27, +        32, +        36, +        49, +        64, +        81, +        100, +        121, +        125, +        128, +        144, +        169, +        196, +        216, +        225, +        243, +        256, +        289, +        324, +        343, +        361, +        400, +        441, +        484, +        512, +        529, +        576, +        625, +        676, +        729, +        784, +        841, +        900, +        961, +        1000, +    }