import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		
		int a = 1;
		
		for(int i = 2; i <= 32; i++) {
			for(int j =2; j <=10; j++) {
				double b = Math.pow(i, j);
				if(b <= X) {
					if(X - a >= X - b) {
						a = (int)b;
					}
				} else {
					break;
				}
			}
		}
		if(X < 4) {
			System.out.println(X);
		} else {
			System.out.println(a);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		
		int a = 1;
		
		for(int i = 2; i <= 32; i++) {
			for(int j =2; j <=10; j++) {
				double b = Math.pow(i, j);
				if(b <= X) {
					if(X - a >= X - b) {
						a = (int)b;
					}
				} else {
					break;
				}
			}
		}
		if(X < 4) {
			System.out.println(X);
		} else {
			System.out.println(a);
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		
		int a = 1;
		
		for(int i = 2; i <= 32; i++) {
			for(int j =2; j <=10; j++) {
				double b = Math.pow(i, j);
				if(b <= X) {
					if(X - a >= X - b) {
						a = (int)b;
					}
				} else {
					break;
				}
			}
		}
		if(X < 4) {
			System.out.println(X);
		} else {
			System.out.println(a);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		
		int a = 1;
		
		for(int i = 2; i <= 32; i++) {
			for(int j =2; j <=10; j++) {
				double b = Math.pow(i, j);
				if(b <= X) {
					if(X - a >= X - b) {
						a = (int)b;
					}
				} else {
					break;
				}
			}
		}
		if(X < 4) {
			System.out.println(X);
		} else {
			System.out.println(a);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X = sc.nextInt(); X sc.nextInt() sc.nextInt sc int a = 1; a 1 for(int i = 2; i <= 32; i++) {
			for(int j =2; j <=10; j++) {
				double b = Math.pow(i, j);
				if(b <= X) {
					if(X - a >= X - b) {
						a = (int)b;
					}
				} else {
					break;
				}
			}
		} int i = 2; int i = 2; i 2 i <= 32 i 32 i++ i++ i {
			for(int j =2; j <=10; j++) {
				double b = Math.pow(i, j);
				if(b <= X) {
					if(X - a >= X - b) {
						a = (int)b;
					}
				} else {
					break;
				}
			}
		} {
			for(int j =2; j <=10; j++) {
				double b = Math.pow(i, j);
				if(b <= X) {
					if(X - a >= X - b) {
						a = (int)b;
					}
				} else {
					break;
				}
			}
		} for(int j =2; j <=10; j++) {
				double b = Math.pow(i, j);
				if(b <= X) {
					if(X - a >= X - b) {
						a = (int)b;
					}
				} else {
					break;
				}
			} int j =2; int j =2; j 2 j <=10 j 10 j++ j++ j {
				double b = Math.pow(i, j);
				if(b <= X) {
					if(X - a >= X - b) {
						a = (int)b;
					}
				} else {
					break;
				}
			} {
				double b = Math.pow(i, j);
				if(b <= X) {
					if(X - a >= X - b) {
						a = (int)b;
					}
				} else {
					break;
				}
			} double b = Math.pow(i, j); b Math.pow(i, j) Math.pow Math i j if(b <= X) {
					if(X - a >= X - b) {
						a = (int)b;
					}
				} else {
					break;
				} b <= X b X {
					if(X - a >= X - b) {
						a = (int)b;
					}
				} if(X - a >= X - b) {
						a = (int)b;
					} X - a >= X - b X - a X a X - b X b {
						a = (int)b;
					} a = (int)b a (int)b {
					break;
				} break; if(X < 4) {
			System.out.println(X);
		} else {
			System.out.println(a);
		} X < 4 X 4 {
			System.out.println(X);
		} System.out.println(X) System.out.println System.out System System.out X {
			System.out.println(a);
		} System.out.println(a) System.out.println System.out System System.out a String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		
		int a = 1;
		
		for(int i = 2; i <= 32; i++) {
			for(int j =2; j <=10; j++) {
				double b = Math.pow(i, j);
				if(b <= X) {
					if(X - a >= X - b) {
						a = (int)b;
					}
				} else {
					break;
				}
			}
		}
		if(X < 4) {
			System.out.println(X);
		} else {
			System.out.println(a);
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		
		int a = 1;
		
		for(int i = 2; i <= 32; i++) {
			for(int j =2; j <=10; j++) {
				double b = Math.pow(i, j);
				if(b <= X) {
					if(X - a >= X - b) {
						a = (int)b;
					}
				} else {
					break;
				}
			}
		}
		if(X < 4) {
			System.out.println(X);
		} else {
			System.out.println(a);
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		
		int a = 1;
		
		for(int i = 2; i <= 32; i++) {
			for(int j =2; j <=10; j++) {
				double b = Math.pow(i, j);
				if(b <= X) {
					if(X - a >= X - b) {
						a = (int)b;
					}
				} else {
					break;
				}
			}
		}
		if(X < 4) {
			System.out.println(X);
		} else {
			System.out.println(a);
		}
	}
}
