import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int res = 1;
    for(int i=2; i<x; i++){
      res = Math.max(res, getMax(x,i));
    }
    System.out.println(res);
  }

  public static int getMax(int x, int w){
    int r = w*w;
    if(r>x) return -1;
    while(r*w<=x){
      r *= w;
    }
    return r;
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int res = 1;
    for(int i=2; i<x; i++){
      res = Math.max(res, getMax(x,i));
    }
    System.out.println(res);
  }

  public static int getMax(int x, int w){
    int r = w*w;
    if(r>x) return -1;
    while(r*w<=x){
      r *= w;
    }
    return r;
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int res = 1;
    for(int i=2; i<x; i++){
      res = Math.max(res, getMax(x,i));
    }
    System.out.println(res);
  } main {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int res = 1;
    for(int i=2; i<x; i++){
      res = Math.max(res, getMax(x,i));
    }
    System.out.println(res);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int res = 1; res 1 for(int i=2; i<x; i++){
      res = Math.max(res, getMax(x,i));
    } int i=2; int i=2; i 2 i<x i x i++ i++ i {
      res = Math.max(res, getMax(x,i));
    } {
      res = Math.max(res, getMax(x,i));
    } res = Math.max(res, getMax(x,i)) res Math.max(res, getMax(x,i)) Math.max Math res getMax(x,i) getMax x i System.out.println(res) System.out.println System.out System System.out res String[] args args public static int getMax(int x, int w){
    int r = w*w;
    if(r>x) return -1;
    while(r*w<=x){
      r *= w;
    }
    return r;
  } getMax {
    int r = w*w;
    if(r>x) return -1;
    while(r*w<=x){
      r *= w;
    }
    return r;
  } int r = w*w; r w*w w w if(r>x) return -1; r>x r x return -1; -1 1 while(r*w<=x){
      r *= w;
    } r*w<=x r*w r w x {
      r *= w;
    } r *= w r w return r; r int x x int w w public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int res = 1;
    for(int i=2; i<x; i++){
      res = Math.max(res, getMax(x,i));
    }
    System.out.println(res);
  }

  public static int getMax(int x, int w){
    int r = w*w;
    if(r>x) return -1;
    while(r*w<=x){
      r *= w;
    }
    return r;
  }
} public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int res = 1;
    for(int i=2; i<x; i++){
      res = Math.max(res, getMax(x,i));
    }
    System.out.println(res);
  }

  public static int getMax(int x, int w){
    int r = w*w;
    if(r>x) return -1;
    while(r*w<=x){
      r *= w;
    }
    return r;
  }
} Main
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int res = 1;
    for(int i=2; i<x; i++){
      res = Math.max(res, getMax(x,i));
    }
    System.out.println(res);
  }

  public static int getMax(int x, int w){
    int r = w*w;
    if(r>x) return -1;
    while(r*w<=x){
      r *= w;
    }
    return r;
  }
}