let () =
  let (x,y) = Scanf.scanf "%d %d\n" (fun x y -> x,y) in
  let y'=int_of_float (sqrt (float_of_int y)) in
  let rec min_yp i =
    if i > x || i > y' then 2
    else if y mod i <> 0 then i
    else min_yp i+1
  in
  let check  =
    if x mod y = 0 then -1
    else if x>y then x
    else x * (min_yp 2)
  in
  let ans = check in
  print_int ans;
  
;;