import Control.Monad.ST import Control.Monad import Data.Array.ST import Data.Array import Data.STRef import Control.Monad import Control.Applicative import Data.List primes ::[Integer] primes = 2:f [3] [3,5..] where f (x:xs) ys = let (ps,qs) = span ( words <$> getLine ::IO [Integer] let p = reverse $ (1:(takeWhile (<=100000) primes)) print $ head [h-(mod h i)| i<-p,l<=h-(mod h i),i<=div (h-(mod h i)) i]