import collections

X = int(eval(input()))



def prime_factorize(n):

    a = []

    while n % 2 == 0:

        a.append(2)

        n //= 2

    f = 3

    while f * f <= n:

        if n % f == 0:

            a.append(f)

            n //= f

        else:

            f += 2

    if n != 1:

        a.append(n)

    return a

ans = 1

for i in range(X):

  Y = X - i

  f = collections.Counter(prime_factorize(Y))

  if len(set(f.values())) == 1 and list(f.values())[0] > 1 :

    ans = Y

    break

print(ans)
import collections

X = int(eval(input()))

def prime_factorize(n):

    a = []

    while n % 2 == 0:

        a.append(2)

        n //= 2

    f = 3

    while f * f <= n:

        if n % f == 0:

            a.append(f)

            n //= f

        else:

            f += 2

    if n != 1:

        a.append(n)

    return a



for i in range(X):

  J = X - i

  d = collections.Counter(prime_factorize(J))

  dv = list(d.values())

  if len(set(dv)) == 1 and dv[0] >= 2:

    print(J)

    break

  if dv == []:

    print((1))

    break

  
import collections

X = int(eval(input()))


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


ans = 1
for i in range(X):
    Y = X - i
    f = collections.Counter(prime_factorize(Y))
    if len(set(f.values())) == 1 and list(f.values())[0] > 1:
        ans = Y
        break
print(ans)

import collections

X = int(eval(input()))


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


for i in range(X):
    J = X - i
    d = collections.Counter(prime_factorize(J))
    dv = list(d.values())
    if len(set(dv)) == 1 and dv[0] >= 2:
        print(J)
        break
    if dv == []:
        print((1))
        break

-ans = 1 -    Y = X - i -    f = collections.Counter(prime_factorize(Y)) -    if len(set(f.values())) == 1 and list(f.values())[0] > 1: -        ans = Y +    J = X - i +    d = collections.Counter(prime_factorize(J)) +    dv = list(d.values()) +    if len(set(dv)) == 1 and dv[0] >= 2: +        print(J) -print(ans) +    if dv == []: +        print((1)) +        break