{-# LANGUAGE TypeApplications #-}

import           Control.Monad
import           Data.List
import qualified Data.Vector.Unboxed as VU

solve :: [Int] -> Int -> Int
solve t n = spl
  where
    vt = VU.fromList t
    subL = VU.concat $ VU.forM (VU.fromList [1..VU.length vt - 1]) $ \x ->
      return $ (vt VU.! (x - 1)) - (vt VU.! x)
    spl = minimum . map (abs . sum) . filter ((==n-1) . length) $ subsequences $ VU.toList subL

main :: IO ()
main = do
  _ : [n] <- map (read @Int) . words <$> getLine
  trees <- map (read @Int) . lines <$> getContents
  let trees' = sort trees
  putStr $ show $ solve trees' n
