import java.math.BigInteger;
import java.util.*;

public class Euler248 {
    static final long TARGET_PHI = 6227020800L;
    static final int DEFAULT_INDEX = 150000;

    static long modMul(long a, long b, long mod) {
        return BigInteger.valueOf(a).multiply(BigInteger.valueOf(b)).mod(BigInteger.valueOf(mod)).longValue();
    }

    static long modPow(long base, long exp, long mod) {
        long out = 1 % mod;
        long cur = base % mod;
        while (exp > 0) {
            if ((exp & 1) != 0)
                out = modMul(out, cur, mod);
            cur = modMul(cur, cur, mod);
            exp >>= 1;
        }
        return out;
    }

    static boolean isPrime(long n) {
        if (n < 2)
            return false;
        long[] smallPrimes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37 };
        for (long p : smallPrimes) {
            if (n == p)
                return true;
            if (n % p == 0)
                return false;
        }

        long d = n - 1;
        int s = 0;
        while ((d & 1) == 0) {
            d >>= 1;
            ++s;
        }

        long[] bases = { 2L, 325L, 9375L, 28178L, 450775L, 9780504L, 1795265022L };

        for (long a : bases) {
            if (a % n == 0)
                continue;
            long x = modPow(a, d, n);
            if (x == 1 || x == n - 1)
                continue;

            boolean witness = true;
            for (int r = 1; r < s; ++r) {
                x = modMul(x, x, n);
                if (x == n - 1) {
                    witness = false;
                    break;
                }
            }
            if (witness)
                return false;
        }
        return true;
    }

    static class Factor {
        long p;
        int e;

        Factor(long p, int e) {
            this.p = p;
            this.e = e;
        }
    }

    static List<Factor> factorize(long n) {
        List<Factor> fac = new ArrayList<>();
        for (long p = 2; p * p <= n; ++p) {
            if (n % p != 0)
                continue;
            int e = 0;
            while (n % p == 0) {
                n /= p;
                ++e;
            }
            fac.add(new Factor(p, e));
        }
        if (n > 1)
            fac.add(new Factor(n, 1));
        return fac;
    }

    static void buildDivisorsDFS(List<Factor> fac, int idx, long cur, List<Long> out) {
        if (idx == fac.size()) {
            out.add(cur);
            return;
        }
        long p = fac.get(idx).p;
        int e = fac.get(idx).e;
        long value = 1;
        for (int i = 0; i <= e; ++i) {
            buildDivisorsDFS(fac, idx + 1, cur * value, out);
            value *= p;
        }
    }

    static List<Long> divisorsOf(long n) {
        List<Factor> fac = factorize(n);
        List<Long> out = new ArrayList<>();
        buildDivisorsDFS(fac, 0, 1, out);
        Collections.sort(out);
        return out;
    }

    static List<Long> candidatePrimes(long phiTarget) {
        List<Long> divs = divisorsOf(phiTarget);
        List<Long> candidates = new ArrayList<>();
        for (long d : divs) {
            long p = d + 1;
            if (isPrime(p)) {
                candidates.add(p);
            }
        }
        Collections.sort(candidates);
        List<Long> uniqueCandidates = new ArrayList<>();
        for (Long c : candidates) {
            if (uniqueCandidates.isEmpty() || !uniqueCandidates.get(uniqueCandidates.size() - 1).equals(c)) {
                uniqueCandidates.add(c);
            }
        }
        return uniqueCandidates;
    }

    static void dfsInverseTotient(long remPhi, int startIdx, BigInteger currentN, List<Long> candidates,
            List<BigInteger> out) {
        if (remPhi == 1) {
            out.add(currentN);
            return;
        }

        for (int i = startIdx; i < candidates.size(); ++i) {
            long p = candidates.get(i);
            long phiPiece = p - 1;
            if (remPhi % phiPiece != 0)
                continue;

            BigInteger nPiece = BigInteger.valueOf(p);
            while (remPhi % phiPiece == 0) {
                dfsInverseTotient(remPhi / phiPiece, i + 1, currentN.multiply(nPiece), candidates, out);

                if (phiPiece > remPhi / p)
                    break;
                phiPiece *= p;
                nPiece = nPiece.multiply(BigInteger.valueOf(p));
            }
        }
    }

    public static String solve() {
        List<Long> candidates = candidatePrimes(TARGET_PHI);
        List<BigInteger> out = new ArrayList<>();

        dfsInverseTotient(TARGET_PHI, 0, BigInteger.ONE, candidates, out);

        Collections.sort(out);
        List<BigInteger> uniqueOut = new ArrayList<>();
        for (BigInteger c : out) {
            if (uniqueOut.isEmpty() || !uniqueOut.get(uniqueOut.size() - 1).equals(c)) {
                uniqueOut.add(c);
            }
        }

        if (DEFAULT_INDEX == 0 || DEFAULT_INDEX > uniqueOut.size())
            return "0";
        return uniqueOut.get(DEFAULT_INDEX - 1).toString();
    }

    public static void main(String[] args) {
        System.out.println(solve());
    }
}
