function main(input) {
    var inputs = input.split('\n')
    var inputMaps = inputs.map((n) => n.split(' ').map((n) => Math.abs(parseInt(n, 10))));
    var eatNumber = inputMap[1][1];
    var cakes = inputMaps.split(1)
                         .map((n) => n.reduce((a,b) => a+b));
    
    var num = cakes.sort((a,b) => b-a)
                   .split(0, eatNumber - 1)
                   .reduce((a,b) => a+b);

    console.log(num);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));