import java.util.*; import java.util.stream.*; class A{ public static void main(String[] $){ Scanner s=new Scanner(System.in); int n=s.nextInt(),k=s.nextInt(); long[]a=LongStream.range(0,n).map(i->s.nextLong()) .sorted() .toArray(); long init=a[n-1]-a[0]; for(int i=n-1;i>0;--i) a[i]-=a[i-1]; a[0]=0; System.out.println( init -Arrays.stream(a) .sorted() .skip(n-k+1) .sum() ); } }