// Arup Guha
// 9/3/2026
// Solution to Codeforces Contest ASC 10 Problem D: More Divisors
// Illustrates sort of a different flavor of backtracking.

import java.util.*;
import java.io.*;

public class moredivisors_inclass {

	final public static int[] PRIMES = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
	final public static int MAXD = 100000;
	final public static long MAXNUM = 10000000000000000L;
	
	// f[i] = min number with i divisors.
	public static long[] f;
	
	public static void main(String[] args) throws Exception {
	
		// Where we store answers.
		f = new long[MAXD+1];
		Arrays.fill(f, -1L);
		
		// Run it!
		go(1, 1, 0, 60);
		
		/*** We put this in initially to get a feel for what the array
		      stored. We learned that a million array slots was overkill.
		
		for (int i=1; i<f.length; i++)
			if (f[i] != -1)
				System.out.println(i+" "+f[i]);
		***/
		
		// Ugh, CF used to do this...
		Scanner stdin = new Scanner(new File("divisors.in"));
		FileWriter fout = new FileWriter(new File("divisors.out"));
		
		/*** This was the original solution - it's fast enough since there's
		     only one query.
		for (int i=f.length-1; i>=0; i--) {
			if (f[i] == -1) continue;
			if (f[i] <= n) {
				fout.write(f[i]+"\n");
				break;
			}
		}
		***/
		
		/*** Here is the optimized solution that would be faster if there were
		     say 100,000 queries.
		***/
		
		// We'll store all the answers that matter in this stack. The stack
		// must only have values in increasing order.
		Stack<Long> mys = new Stack<Long>();
		
		// Go in order of number of divisors.
		for (int i=1; i<f.length; i++) {
			if (f[i] == -1) continue;
			
			// If this is true, then those values are never answers to queries,
			// as we found a smaller number with more divisors.
			while (mys.size() > 0 && f[i] < mys.peek())
				mys.pop();
			
			// This is our first answer with i divisors, so we must push it.
			mys.push(f[i]);
		}
		
		// Now, just move these items into an ordered set for fast queries.
		TreeSet<Long> ts = new TreeSet<Long>();
		while (mys.size() > 0) ts.add(mys.pop());
		
		// Once we have the set, we can handle each query in log time of the original
		// stack size.
		long n = stdin.nextLong();
		long res = ts.lower(n+1);
		fout.write(res+"\n");
		fout.close();
	}
	
	// Fills in our table with all relevant answers that are multiples of curVal.
	// curVal must have numF factors, and the next prime number to put in is the
	// one in index pI, and that prime was raised to index lastE.
	public static void go(long curVal, int numF, int pI, int lastE) {
	
		// Update my best, if necessary.
		if (f[numF] == -1) 
			f[numF] = curVal;
		else if (curVal < f[numF])
			f[numF] = curVal;
			
		// What I will be multiplying into curVal.
		long multIn = PRIMES[pI];
		
		// Try each possible value of the exponent to this prime.
		for (int i=1; i<=lastE; i++) {
		
			// Too big, get out.
			if (multIn*curVal > MAXNUM) break;
			
			// Try multiplying in this prime to exponent i.
			go(multIn*curVal, numF*(i+1), pI+1, i);
			
			// Update our multiply in value to the next exponent.
			multIn *= PRIMES[pI];
		}
	}
}
