'use strict'

function main(s) {
  s = s.split('\n').slice(0, -1);

  const N = Number(s[0].split(' ')[0]);
  const K = Number(s[0].split(' ')[1]);
  const bars = s[1].split(' ').map(n => Number(n));
  bars.sort((a, b) => a - b);

  const ans = bars.slice(N - K).reduce((a, b) => a + b);
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
