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) { ans = i; break; } } else { if ((a + sum / i) % b == 0 && (b + sum / i) % a == 0) { ans = sum / i; break; } } } System.out.println(ans); } }