def lscan; gets.split.map(&:to_i); end a,b = lscan if [a,b].min == 1 p 0 elsif a.gcd(b) == 1 l = a.lcm(b)+1 v = [1]*(l) v[0] = 0 (l).times do |i| if v[i] == 0 v[i+a] = 0 if v[i+a] v[i+b] = 0 if v[i+b] end end p v.reduce(:+) else p -1 end