import Data.List
f s
 |null s=[]
 |null (init s)=[]
 |otherwise=(s!!1-s!!0):(f (tail s))
main=do
 [n,k]<-map read.words<$>getLine
 s<-map read.words<$>getLine
 print$sum$drop(n-1)(sortBy(flip compare)(f (sort s)))
 