// Arup Guha
// 11/8/2012
// Solution to 2011 South East Regional Problem C: Flooring Tiles

import java.util.*;

public class c {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);

		int n = stdin.nextInt();

		while (n != 0) {

			// Kind of a special case.
			if (n == 1)
				System.out.println("1");

			// Regular case.
			else {

				// Try finding the smallest number with 2n-1 and 2n factors.
				int[] factors = new int[7];
				Long tryOne = min(factors, 0, 2, 2*n-1);
				Long tryTwo = min(factors, 0, 2, 2*n);

				// My code might return null, if the answer exceeds 10^18, so
				// I have to do null checks here.
				Long ans = tryOne;
				if (ans == null)
					ans = tryTwo;
				else if (tryTwo != null && tryTwo < ans)
					ans = tryTwo;
				System.out.println(ans);
			}
			n = stdin.nextInt();
		}
	}

	// When rest = 1, that's the base case and factors will store one
	// unique factorization of a number. That factorization is then used to
	// create the minimum value that has that many prime factors.
	// If rest isn't one, factors stores all the factors we've created and
	// and rest is what we have to factorize, where the lowest factor is low.
	// k is the next spot to fill in.
	public static Long min(int[] factors, int k, int low, int rest) {

		// No solution.
		if (rest > 1 && rest < low) return null;

		// Form the number and return.
		if (rest == 1)
			return value(factors, k);

		Long ans = null;

		// Try each number for the next number.
		for (int next = low; next <= rest/next; next++) {

			// This can be our next factor, so try it.
			if (rest%next == 0) {

				// Fill in and solve recursively.
				factors[k] = next;
				Long temp = min(factors, k+1, next, rest/next);

				if (temp != null && (ans == null || temp < ans))
					ans = temp;
			}

		}

		// I put in this case separately, since I didn't want the loop above
		// generating lots of invalid cases.
		factors[k] = rest;
		Long temp = min(factors, k+1, rest, 1);
		if (temp != null && (ans == null || temp < ans))
			ans = temp;

		return ans;
	}

	// Returns the value of the number with the given prime factorization.
	// k represents the number of primes we are considering.
	public static Long value(int[] factors, int k) {

		int[] p = {2, 3, 5, 7, 11, 13, 17};

		// The log is to avoid overflow errors.
		Long ans = 1L;
		double logVal = 0;
		for (int i=0, j=k-1; i<k; i++,j--) {

			for (int loop=0; loop<factors[i]-1; loop++) {
				ans = ans*p[j];
				logVal += Math.log10(p[j]);
			}
		}

		if (logVal > 18.01) return null;
		return ans;
	}
}