
import Data.List
import Control.Monad

foo :: Int -> Int -> Int
foo x y = x*y `mod` 2019

hoge :: [Int] -> [Int] -> [Int]
hoge xs ys = do
  x <- xs
  y <- ys
  guard (x<y)
  return $ foo x y

main = do
  sd <- map read . words <$> getLine :: IO [Int]
  let nums = map (`mod` 2019) [head sd..last sd]
  if 0 `elem` nums then print 0
  else print $ foldr min 2019 $ hoge nums nums


