#include <bits/stdc++.h>
int main() {
  std::size_t numberOfFruit = 0;
  std::size_t numberOfFruitKind = 0;
  std::cin >> numberOfFruit >> numberOfFruitKind;
  std::vector<int> priceList;
  priceList.reserve(numberOfFruitKind);
  for (std::size_t index = 0; index < numberOfFruitKind; ++index) {
    int inPrice = 0;
    std::cin >> inPrice;
    priceList.emplace_back(inPrice);
  }
  for (std::size_t index = numberOfFruitKind; index < numberOfFruit; ++index) {
    int inPrice = 0;
    std::cin >> inPrice;
    for (std::size_t priceListIndex = 0; priceListIndex < numberOfFruitKind;
         ++priceListIndex) {
      if (inPrice < priceList[priceListIndex]) {
        priceList[priceListIndex] = inPrice;
        break;
      }
    }
  }
  const int totalPrice = [&priceList]() {
    int ret = 0;
    for (int price : priceList) {
      ret += price;
    }
    return ret;
  }();
  std::cout << totalPrice << std::endl;
}
