main=map read.words<$>getLine>>=print.(\x->if x!!0>=x!!1 then 0 else(f(x!!0)(x!!1)(x!!0)((x!!0)+1)2019)).(\x->(if x!!1-x!!0>2019 then[0,0] else[mod y 2019|y<-x]))
 where f l r i j a = if j>r then a else(f l r (i+(if j==r then 1 else 0))(if j==r then (i+2) else (j+1))(min a(mod(i*j)2019)))