import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long a = sc.nextInt(); long b = sc.nextInt(); long sum = a + b; long ans = -1; for (long i = 1; i <= Math.sqrt(sum); i++) { if (sum % i == 0) { if ((a + i) % b == 0 && (b + i) % a == 0 && a != i && b != i) { ans = i; break; } if ((a + sum / i) % b == 0 && (b + sum / i) % a == 0 && a != sum / i && b != sum / i) { ans = sum / i; } } } System.out.println(ans); } }