import java.io.*; import java.util.Scanner; public class Main_yukicoder816 { private static Scanner sc; private static Printer pr; private static void solve() { int a = sc.nextInt(); int b = sc.nextInt(); int ab = a + b; for (long c = 1; c * c <= ab; c++) { if (ab % c == 0) { if (check(a, b, c)) { pr.println(c); return; } if (c != ab / c) { if (check(a, b, ab / c)) { pr.println(ab / c); return; } } } } pr.println(-1); } private static boolean check(int a, int b, long c) { if (a == b || b == c || c == a) { return false; } if ((a + b) % c == 0 && (b + c) % a == 0 && (c + a) % b == 0) { return true; } else { return false; } } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes())); pr = new Printer(System.out); solve(); // pr.close(); pr.flush(); // sc.close(); } static String INPUT = null; private static class Printer extends PrintWriter { Printer(OutputStream out) { super(out); } } }