import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B
main=print.solve.map(fst.fromJust.B.readInt).B.words=<<B.getContents
solve(n:m:xs)=foldr(+)0.take(m-n).sort.(zipWith(-)=<<tail).sort$xs