{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TemplateHaskell #-}
--atcoder {-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NoImplicitPrelude #-}

import Prelude
import System.IO
import System.Environment
import System.Exit
import Data.List
import Data.Maybe
import qualified Data.Char as Char
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import qualified Control.Monad
--atcoder import qualified Data.Semigroup
import qualified Data.Map as Map
import qualified Data.Set as Set

readInt :: IO Int
--readInt = read <$> getLine
readInt = getLine >>= (return . read)

readInts :: IO [Int]
readInts = map (read :: String -> Int) <$> words <$> getLine

bf :: Int -> Int -> Map.Map (Int, Int) Int -> Int
bf l r mp | l >= r = maxBound :: Int
          | memo /= Nothing = fromJust memo
          | otherwise = minimum [ret, bf (l+1) r new_memo, bf l (r-1) new_memo]
          where ret = mod (l*r) 2019
                memo = Map.lookup (l, r) mp
                new_memo = Map.insert (l, r) ret mp
       

solve :: Int -> Int -> Int
solve l r = if r - l + 1 >= 2019
            then 0
            else bf l r (Map.empty :: Map.Map (Int, Int) Int)

main :: IO ()
main = do
    lr <- getLine >>= (return . words) >>= (return . map (read :: String -> Int))
    let l = lr !! 0
    let r = lr !! 1
    let ret = solve l r
    print ret