import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
main=B.interact$B.pack.show.f.unfoldr(B.readInt.B.dropWhile isSpace)
f (n:k:h)=minimum$zipWith(-)hs ss where
 hh=sort h
 ss=take(n-k+1)hh
 hs=drop(k-1)hh