import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (unfoldr)

main :: IO ()
main = do
  (l : r : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  print $ f l r

f :: Int -> Int -> Int
f l r | p 673 && p 3 = 0
      | otherwise = minimum (concat $ unfoldr next [(l `mod` 2019)..(r `mod` 2019)])
  where
    next :: [Int] -> Maybe ([Int], [Int])
    next [] = Nothing
    next (x : xs) = Just (map ((`mod` 2019) . (x *)) xs, xs)
    p :: Int -> Bool
    p d = l `div` d < (r + 1) `div` d

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
