
import java.util.*;
import java.lang.*;

import static java.lang.StrictMath.abs;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        double[] ans = new double[331];
        ans[0] = 0;
        double a = 0;
        double b =0;

       for(double i =1; i< 33; i++){
           for(double k = 2; k < 10; k++){
               a = Math.pow(i,k);
               if(a<=x&& x-a < x- b){
                   b =a;
  
               }
           }

       }
        System.out.println((int)b);



        }

    } import java.util.*; util.* java import java.lang.*; lang.* java import static java.lang.StrictMath.abs; import static java.lang.StrictMath.abs; import static java.lang.StrictMath.abs; class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        double[] ans = new double[331];
        ans[0] = 0;
        double a = 0;
        double b =0;

       for(double i =1; i< 33; i++){
           for(double k = 2; k < 10; k++){
               a = Math.pow(i,k);
               if(a<=x&& x-a < x- b){
                   b =a;
  
               }
           }

       }
        System.out.println((int)b);



        }

    } Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        double[] ans = new double[331];
        ans[0] = 0;
        double a = 0;
        double b =0;

       for(double i =1; i< 33; i++){
           for(double k = 2; k < 10; k++){
               a = Math.pow(i,k);
               if(a<=x&& x-a < x- b){
                   b =a;
  
               }
           }

       }
        System.out.println((int)b);



        } main {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        double[] ans = new double[331];
        ans[0] = 0;
        double a = 0;
        double b =0;

       for(double i =1; i< 33; i++){
           for(double k = 2; k < 10; k++){
               a = Math.pow(i,k);
               if(a<=x&& x-a < x- b){
                   b =a;
  
               }
           }

       }
        System.out.println((int)b);



        } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc double[] ans = new double[331]; ans new double[331] 331 ans[0] = 0 ans[0] ans 0 0 double a = 0; a 0 double b =0; b 0 for(double i =1; i< 33; i++){
           for(double k = 2; k < 10; k++){
               a = Math.pow(i,k);
               if(a<=x&& x-a < x- b){
                   b =a;
  
               }
           }

       } double i =1; double i =1; i 1 i< 33 i 33 i++ i++ i {
           for(double k = 2; k < 10; k++){
               a = Math.pow(i,k);
               if(a<=x&& x-a < x- b){
                   b =a;
  
               }
           }

       } {
           for(double k = 2; k < 10; k++){
               a = Math.pow(i,k);
               if(a<=x&& x-a < x- b){
                   b =a;
  
               }
           }

       } for(double k = 2; k < 10; k++){
               a = Math.pow(i,k);
               if(a<=x&& x-a < x- b){
                   b =a;
  
               }
           } double k = 2; double k = 2; k 2 k < 10 k 10 k++ k++ k {
               a = Math.pow(i,k);
               if(a<=x&& x-a < x- b){
                   b =a;
  
               }
           } {
               a = Math.pow(i,k);
               if(a<=x&& x-a < x- b){
                   b =a;
  
               }
           } a = Math.pow(i,k) a Math.pow(i,k) Math.pow Math i k if(a<=x&& x-a < x- b){
                   b =a;
  
               } a<=x&& x-a < x- b a<=x a x x-a < x- b x-a x a x- b x b {
                   b =a;
  
               } b =a b a System.out.println((int)b) System.out.println System.out System System.out (int)b String[] args args

import java.util.*;
import java.lang.*;

import static java.lang.StrictMath.abs;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        double[] ans = new double[331];
        ans[0] = 0;
        double a = 0;
        double b =0;

       for(double i =1; i< 33; i++){
           for(double k = 2; k < 10; k++){
               a = Math.pow(i,k);
               if(a<=x&& x-a < x- b){
                   b =a;
  
               }
           }

       }
        System.out.println((int)b);



        }

    }