import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); sc.close(); int max = (int) Math.sqrt(a + b); for (int i = 1; i <= max; i++) { if (a == i || b == i) { continue; } if ((a + b) % i == 0 && (a + i) % b == 0 && (i + b) % a == 0) { System.out.println(i); return; } } System.out.println(-1); } }