using System.Collections.Generic; using System.Linq; using System; public class Hello { static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var a = int.Parse(line[0]); var b = int.Parse(line[1]); var ab = a + b; var t = new List(); for (int i = 1; i * i <= ab; i++) if (ab % i == 0) if (i * i != ab) { t.Add(i); t.Add(ab / i); } else t.Add(i); t.Sort(); var ans = getAns(a, b, t); Console.WriteLine(ans); } static int getAns(int a, int b, List t) { var tc = t.Count(); for (int i = 0; i < tc; i++) { var w = t[i]; if (a != w && b != w && (w + a) % b == 0 && (w + b) % a == 0) return w; } return -1; } }