let rec for_fold a b v f = if a > b then v else for_fold (a+1) b (f a v) f
let ans =
  Scanf.scanf "%d %d" @@ fun l r ->
  if r - l >= 5000 then 0 else
  for_fold l     r max_int @@ fun i a ->
  for_fold (i+1) r a       @@ fun j a -> min a (i * j mod 2019)
let () = Printf.printf "%d\n" ans
