#!/usr/local/gnu/bin/bash

function bubble_sort(){
    local arr=($@)
    local i j
    local tmp
    for i in `seq 0 $((${#arr[@]}-1))`
    do
        for j in `seq 1 $((${#arr[@]}-i+1))`
        do
            if((arr[j]<arr[j-1]))
            then
                tmp=${arr[j]}
                arr[$j]=${arr[j-1]}
                arr[$j-1]=$tmp
            fi
        done
    done
    echo ${arr[@]}
}

function sum(){
    local result=0
    local i
    for i in $@
    do
        result=$((result+i))
    done
    echo $result
}


read n k
read -a arr
arr=(`bubble_sort ${arr[@]}`)
sum ${arr[@]:n-k}