local a, b = io.read("*n", "*n") -- (1, 2, 5), (1, 3, 3), (2, 2, 2) local t1 = {1, 1, 2, 2, 5, 5, 1, 3, 3, 2} local t2 = {2, 5, 1, 5, 1, 2, 3, 1, 3, 2} local t3 = {5, 2, 5, 1, 2, 1, 3, 3, 1, 2} local ccand = -1 for i = 1, 10 do if((a + b) % t1[i] == 0) then local c = (a + b) / t1[i] if((b + c) == t2[i] * a and (c + a) == t3[i] * b) then if(ccand == -1) then ccand = c else ccand = math.min(ccand, c) end end end end print(ccand)