import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.IntMap as IM
import Data.List

type Map = IM.IntMap Int

readIntLines :: IO [Int]
readIntLines = map (fst . fromJust . BC.readInt) . BC.lines <$> BC.getContents

get :: Int -> Map -> Int
get key m = fromMaybe 0 $ IM.lookup key m

solve :: Int -> Int -> Map -> [Int]
solve k right m
  | left <= 0 = []
  | otherwise = get right m - get left m : solve k (right - 1) m
    where left = right - k + 1

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine
  hs <- sort <$> readIntLines
  let d = IM.fromList $ zip [1..] hs
  print . minimum $ solve k (length hs) d