#include <bits/stdc++.h>

using namespace std;

int main()
{
    int k,n;
    cin >> n >> k;
    int a[n];
    int r = 0;

    for (int i = 0; i < n; i++)
        cin >> a[i];

    sort (a, a + n);

    for (int i = n - 1; i >= n - k + 1; i--) r += a[i];
    r -= a[0];

    cout<<r;
    return 0;
}