import * as fs from 'fs';
 
const input = fs.readFileSync("/dev/stdin", "utf8");
 
const [, kindsToBuy, ...prices] = input.split(/\s/g).map(i => parseInt(i, 10));
const lowestPrices = prices.sort((a, b) => a >= b ? 1 : -1).slice(0, kindsToBuy);
const totalPrice = lowestPrices.reduce((acc, crr) => acc+crr, 0);
console.log(totalPrice);
