require 'prime' a,b = gets.split.map(&:to_i) d = Prime.prime_division(a+b) $p = [] def div(c,d,i) if i == d.size $p << c else div(c,d,i+1) d[i][1].times do |j| div(c*(d[i][0]**(j+1)),d,i+1) end end end div(1,d,0) $p.sort! $p.each do |i| if (a+b)%i == 0 && (b+i)%a == 0 && (i+a)%b == 0 && a != i && b != i puts i exit end end puts "-1"