#include <stdio.h>
#include <stdlib.h>
#include <math.h>

struct {
    double dif;
    int in;
} b[200000], t;

void fun(long a[], long n)
{
    long long sum = 0;
    for(int i = 0; i < n; i++) {
        sum += a[i];
    }
    double as = 1.0 * sum / n;

    for(int i = 0; i < n; i++) {
        b[i].dif = fabs(a[i] - as);
        b[i].in = i;
    }
    for(int i = 0; i < (n-1); i++) {
        for(int j = 1; j < n; j++) {
            if(b[i].dif > b[j].dif) {
                t = b[i];
                b[i] = b[j];
                b[j] = t;
            }
        }
    }
}

int main()
{
    int i, j;
    long n, k;
    scanf("%ld %ld", &n, &k);

    long a[n], unused = (n-k);
    for(i = 0; i < n; i++) {
        scanf("%ld", &a[i]);
    }

    fun(a, n);

    for(i = 0; i < unused; i++) {
        a[b[i].in] = 0;
    }

    for(i = 0, j = (n-1); i < j; ) {
        while((a[i] == 0) && (i < j)) i++;
        while((a[j] == 0) && (i < j)) j--;

        if(i < j) {
            if((a[i] - a[j]) > (a[j] - a[i])) {
                a[i] = a[i] - a[j];
                a[j] = 0;
            }
            else {
                a[j] = a[j] - a[i];
                a[i] = 0;
            }
        }
    }

    printf("%ld", a[i]);

    return 0;
}