import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solverS.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int X = Integer.parseInt(strArr[0]);
		initPrimeNums(X);
		int ans = X;
		for (; ans > 1 && (!check(ans)); ans--) {
		}
		System.out.println(ans);
	}

	ArrayList<Integer> PrimeNums;

	private void initPrimeNums(int x) {
		int[] pnchk = new int[x + 1];
		PrimeNums = new ArrayList<Integer>();
		for (int i = 2; i < pnchk.length; i++) {
			if (pnchk[i] >= 0) {
				for (int j = i + i; j < pnchk.length; j += i)
					pnchk[j] = -1;
				PrimeNums.add(i);
			}
		}
		// for (int i : PrimeNums)
		// System.out.print(" " + i);
		// System.out.println();
	}

	private boolean check(int num) {
		HashMap<Integer, Integer> fact = factorization(num);
		int p = 0;
		for (int b : fact.keySet()) {
			// System.out.println(num + " " + b + " " + fact.get(b));
			if (fact.get(b) < 2)
				return false;
			if (p == 0)
				p = fact.get(b);
			if (p != fact.get(b))
				return false;
		}
		return true;
	}

	private HashMap<Integer, Integer> factorization(int num) {
		HashMap<Integer, Integer> ret = new HashMap<Integer, Integer>();
		for (int n = num; n > 1;) {
			for (int b : PrimeNums) {
				if (n % b == 0) {
					n /= b;
					if (ret.containsKey(b))
						ret.put(b, ret.get(b) + 1);
					else
						ret.put(b, 1);
				}
			}
		}
		return ret;
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.util.HashMap; HashMap java.util class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solverS.solve();
	}
} Main public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solverS.solve();
	} main {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solverS.solve();
	} BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) Solver solver = new Solver(); solver new Solver() solver.init() solver.init solver solver.readHead(in.readLine()) solver.readHead solver in.readLine() in.readLine in String args[] args class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int X = Integer.parseInt(strArr[0]);
		initPrimeNums(X);
		int ans = X;
		for (; ans > 1 && (!check(ans)); ans--) {
		}
		System.out.println(ans);
	}

	ArrayList<Integer> PrimeNums;

	private void initPrimeNums(int x) {
		int[] pnchk = new int[x + 1];
		PrimeNums = new ArrayList<Integer>();
		for (int i = 2; i < pnchk.length; i++) {
			if (pnchk[i] >= 0) {
				for (int j = i + i; j < pnchk.length; j += i)
					pnchk[j] = -1;
				PrimeNums.add(i);
			}
		}
		// for (int i : PrimeNums)
		// System.out.print(" " + i);
		// System.out.println();
	}

	private boolean check(int num) {
		HashMap<Integer, Integer> fact = factorization(num);
		int p = 0;
		for (int b : fact.keySet()) {
			// System.out.println(num + " " + b + " " + fact.get(b));
			if (fact.get(b) < 2)
				return false;
			if (p == 0)
				p = fact.get(b);
			if (p != fact.get(b))
				return false;
		}
		return true;
	}

	private HashMap<Integer, Integer> factorization(int num) {
		HashMap<Integer, Integer> ret = new HashMap<Integer, Integer>();
		for (int n = num; n > 1;) {
			for (int b : PrimeNums) {
				if (n % b == 0) {
					n /= b;
					if (ret.containsKey(b))
						ret.put(b, ret.get(b) + 1);
					else
						ret.put(b, 1);
				}
			}
		}
		return ret;
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
} Solver int N; N int cnt; cnt ArrayList<Integer> PrimeNums; PrimeNums public void init() {
		N = 0;
		cnt = 0;
	} init {
		N = 0;
		cnt = 0;
	} N = 0 N 0 cnt = 0 cnt 0 public void readHead(String str) {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int X = Integer.parseInt(strArr[0]);
		initPrimeNums(X);
		int ans = X;
		for (; ans > 1 && (!check(ans)); ans--) {
		}
		System.out.println(ans);
	} readHead {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int X = Integer.parseInt(strArr[0]);
		initPrimeNums(X);
		int ans = X;
		for (; ans > 1 && (!check(ans)); ans--) {
		}
		System.out.println(ans);
	} String[] strArr = str.split(" "); strArr str.split(" ") str.split str " " int X = Integer.parseInt(strArr[0]); X Integer.parseInt(strArr[0]) Integer.parseInt Integer strArr[0] strArr 0 initPrimeNums(X) initPrimeNums X int ans = X; ans X for (; ans > 1 && (!check(ans)); ans--) {
		} ; ans > 1 && (!check(ans)) ans > 1 ans 1 (!check(ans)) check(ans) check ans ans-- ans-- ans {
		} {
		} System.out.println(ans) System.out.println System.out System System.out ans String str str private void initPrimeNums(int x) {
		int[] pnchk = new int[x + 1];
		PrimeNums = new ArrayList<Integer>();
		for (int i = 2; i < pnchk.length; i++) {
			if (pnchk[i] >= 0) {
				for (int j = i + i; j < pnchk.length; j += i)
					pnchk[j] = -1;
				PrimeNums.add(i);
			}
		}
		// for (int i : PrimeNums)
		// System.out.print(" " + i);
		// System.out.println();
	} initPrimeNums {
		int[] pnchk = new int[x + 1];
		PrimeNums = new ArrayList<Integer>();
		for (int i = 2; i < pnchk.length; i++) {
			if (pnchk[i] >= 0) {
				for (int j = i + i; j < pnchk.length; j += i)
					pnchk[j] = -1;
				PrimeNums.add(i);
			}
		}
		// for (int i : PrimeNums)
		// System.out.print(" " + i);
		// System.out.println();
	} int[] pnchk = new int[x + 1]; pnchk new int[x + 1] x + 1 x 1 PrimeNums = new ArrayList<Integer>() PrimeNums new ArrayList<Integer>() for (int i = 2; i < pnchk.length; i++) {
			if (pnchk[i] >= 0) {
				for (int j = i + i; j < pnchk.length; j += i)
					pnchk[j] = -1;
				PrimeNums.add(i);
			}
		} int i = 2; int i = 2; i 2 i < pnchk.length i pnchk.length pnchk pnchk.length i++ i++ i {
			if (pnchk[i] >= 0) {
				for (int j = i + i; j < pnchk.length; j += i)
					pnchk[j] = -1;
				PrimeNums.add(i);
			}
		} {
			if (pnchk[i] >= 0) {
				for (int j = i + i; j < pnchk.length; j += i)
					pnchk[j] = -1;
				PrimeNums.add(i);
			}
		} if (pnchk[i] >= 0) {
				for (int j = i + i; j < pnchk.length; j += i)
					pnchk[j] = -1;
				PrimeNums.add(i);
			} pnchk[i] >= 0 pnchk[i] pnchk i 0 {
				for (int j = i + i; j < pnchk.length; j += i)
					pnchk[j] = -1;
				PrimeNums.add(i);
			} for (int j = i + i; j < pnchk.length; j += i)
					pnchk[j] = -1; int j = i + i; int j = i + i; j i + i i i j < pnchk.length j pnchk.length pnchk pnchk.length j += i j += i j i pnchk[j] = -1; pnchk[j] = -1 pnchk[j] pnchk j -1 1 PrimeNums.add(i) PrimeNums.add PrimeNums i int x x private boolean check(int num) {
		HashMap<Integer, Integer> fact = factorization(num);
		int p = 0;
		for (int b : fact.keySet()) {
			// System.out.println(num + " " + b + " " + fact.get(b));
			if (fact.get(b) < 2)
				return false;
			if (p == 0)
				p = fact.get(b);
			if (p != fact.get(b))
				return false;
		}
		return true;
	} check {
		HashMap<Integer, Integer> fact = factorization(num);
		int p = 0;
		for (int b : fact.keySet()) {
			// System.out.println(num + " " + b + " " + fact.get(b));
			if (fact.get(b) < 2)
				return false;
			if (p == 0)
				p = fact.get(b);
			if (p != fact.get(b))
				return false;
		}
		return true;
	} HashMap<Integer, Integer> fact = factorization(num); fact factorization(num) factorization num int p = 0; p 0 for (int b : fact.keySet()) {
			// System.out.println(num + " " + b + " " + fact.get(b));
			if (fact.get(b) < 2)
				return false;
			if (p == 0)
				p = fact.get(b);
			if (p != fact.get(b))
				return false;
		} int b fact.keySet() fact.keySet fact {
			// System.out.println(num + " " + b + " " + fact.get(b));
			if (fact.get(b) < 2)
				return false;
			if (p == 0)
				p = fact.get(b);
			if (p != fact.get(b))
				return false;
		} {
			// System.out.println(num + " " + b + " " + fact.get(b));
			if (fact.get(b) < 2)
				return false;
			if (p == 0)
				p = fact.get(b);
			if (p != fact.get(b))
				return false;
		} if (fact.get(b) < 2)
				return false; fact.get(b) < 2 fact.get(b) fact.get fact b 2 return false; false if (p == 0)
				p = fact.get(b); p == 0 p 0 p = fact.get(b) p fact.get(b) fact.get fact b if (p != fact.get(b))
				return false; p != fact.get(b) p fact.get(b) fact.get fact b return false; false return true; true int num num private HashMap<Integer, Integer> factorization(int num) {
		HashMap<Integer, Integer> ret = new HashMap<Integer, Integer>();
		for (int n = num; n > 1;) {
			for (int b : PrimeNums) {
				if (n % b == 0) {
					n /= b;
					if (ret.containsKey(b))
						ret.put(b, ret.get(b) + 1);
					else
						ret.put(b, 1);
				}
			}
		}
		return ret;
	} factorization {
		HashMap<Integer, Integer> ret = new HashMap<Integer, Integer>();
		for (int n = num; n > 1;) {
			for (int b : PrimeNums) {
				if (n % b == 0) {
					n /= b;
					if (ret.containsKey(b))
						ret.put(b, ret.get(b) + 1);
					else
						ret.put(b, 1);
				}
			}
		}
		return ret;
	} HashMap<Integer, Integer> ret = new HashMap<Integer, Integer>(); ret new HashMap<Integer, Integer>() for (int n = num; n > 1;) {
			for (int b : PrimeNums) {
				if (n % b == 0) {
					n /= b;
					if (ret.containsKey(b))
						ret.put(b, ret.get(b) + 1);
					else
						ret.put(b, 1);
				}
			}
		} int n = num; int n = num; n num n > 1 n 1 {
			for (int b : PrimeNums) {
				if (n % b == 0) {
					n /= b;
					if (ret.containsKey(b))
						ret.put(b, ret.get(b) + 1);
					else
						ret.put(b, 1);
				}
			}
		} {
			for (int b : PrimeNums) {
				if (n % b == 0) {
					n /= b;
					if (ret.containsKey(b))
						ret.put(b, ret.get(b) + 1);
					else
						ret.put(b, 1);
				}
			}
		} for (int b : PrimeNums) {
				if (n % b == 0) {
					n /= b;
					if (ret.containsKey(b))
						ret.put(b, ret.get(b) + 1);
					else
						ret.put(b, 1);
				}
			} int b PrimeNums {
				if (n % b == 0) {
					n /= b;
					if (ret.containsKey(b))
						ret.put(b, ret.get(b) + 1);
					else
						ret.put(b, 1);
				}
			} {
				if (n % b == 0) {
					n /= b;
					if (ret.containsKey(b))
						ret.put(b, ret.get(b) + 1);
					else
						ret.put(b, 1);
				}
			} if (n % b == 0) {
					n /= b;
					if (ret.containsKey(b))
						ret.put(b, ret.get(b) + 1);
					else
						ret.put(b, 1);
				} n % b == 0 n % b n b 0 {
					n /= b;
					if (ret.containsKey(b))
						ret.put(b, ret.get(b) + 1);
					else
						ret.put(b, 1);
				} n /= b n b if (ret.containsKey(b))
						ret.put(b, ret.get(b) + 1);
					else
						ret.put(b, 1); ret.containsKey(b) ret.containsKey ret b ret.put(b, ret.get(b) + 1) ret.put ret b ret.get(b) + 1 ret.get(b) ret.get ret b 1 ret.put(b, 1) ret.put ret b 1 return ret; ret int num num public boolean hasNext() {
		return cnt < N;
	} hasNext {
		return cnt < N;
	} return cnt < N; cnt < N cnt N public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	} readBody {
		// System.out.println(str);
		cnt++;
	} cnt++ cnt String str str public void solve() {

	} solve {

	}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solverS.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int X = Integer.parseInt(strArr[0]);
		initPrimeNums(X);
		int ans = X;
		for (; ans > 1 && (!check(ans)); ans--) {
		}
		System.out.println(ans);
	}

	ArrayList<Integer> PrimeNums;

	private void initPrimeNums(int x) {
		int[] pnchk = new int[x + 1];
		PrimeNums = new ArrayList<Integer>();
		for (int i = 2; i < pnchk.length; i++) {
			if (pnchk[i] >= 0) {
				for (int j = i + i; j < pnchk.length; j += i)
					pnchk[j] = -1;
				PrimeNums.add(i);
			}
		}
		// for (int i : PrimeNums)
		// System.out.print(" " + i);
		// System.out.println();
	}

	private boolean check(int num) {
		HashMap<Integer, Integer> fact = factorization(num);
		int p = 0;
		for (int b : fact.keySet()) {
			// System.out.println(num + " " + b + " " + fact.get(b));
			if (fact.get(b) < 2)
				return false;
			if (p == 0)
				p = fact.get(b);
			if (p != fact.get(b))
				return false;
		}
		return true;
	}

	private HashMap<Integer, Integer> factorization(int num) {
		HashMap<Integer, Integer> ret = new HashMap<Integer, Integer>();
		for (int n = num; n > 1;) {
			for (int b : PrimeNums) {
				if (n % b == 0) {
					n /= b;
					if (ret.containsKey(b))
						ret.put(b, ret.get(b) + 1);
					else
						ret.put(b, 1);
				}
			}
		}
		return ret;
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}
