import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  d <- getl toInt
  unless (d == 0) $ do
    n <- getl toInt
    m <- getl toInt
    ss <- replicateM (n-1) (getl toInt)
    hs <- replicateM m (getl toInt)
    print $ solve d (0:ss) hs
    main

solve :: Int -> [Int] -> [Int] -> Int
solve d ss = sum . map f
  where
    dst x y = let z = abs (x - y) in min z (d - z)
    f h = minimum $ map (dst h) ss

toInt :: String -> Int
toInt = read

getl :: (String -> a) -> IO a
getl f = f <$> getLine