let () =
  let (x,y) = Scanf.scanf "%d %d" (fun x y -> x,y) in
  let rec minp y i =
    if y mod i = 0 then i
    else minp y i+1
  in
  let check x y  =
    if x mod y = 0 then -1
    else x * (minp y 2 - 1)
  in
  let ans = check x y in
  print_int ans;

