#K64797. Smallest GBF Finder

    ID: 32055 Type: Default 1000ms 256MiB

Smallest GBF Finder

Smallest GBF Finder

Given two positive integers (A) and (B), find the smallest integer (X) such that (X \ge 2) and (X \le \min(A, B)) and both [ gcd(X, A) > 1 \quad \text{and} \quad gcd(X, B) > 1 ] hold true. If no such integer exists, output (-1).

Here, (gcd(a, b)) denotes the greatest common divisor of (a) and (b). The solution should read the two integers from standard input and write the answer to standard output.

inputFormat

The input consists of a single line containing two space-separated integers (A) and (B).

outputFormat

Output a single integer, which is the smallest integer (X) satisfying the conditions, or (-1) if no such integer exists.## sample

12 15
3