#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, k, hasilsementara;
  cin >> a >> k;
  int hola[a];
  int temp[k];
  for (int haleluyah = 0; haleluyah < k; haleluyah++) {
    temp[haleluyah] = 1000000;
  }
  for (int i = 0; i < a; i++) {
    cin >> hola[i];
    for (int j = 0; j < k; j++) {
      if (hola[i] < temp[j]) {
        temp[j] = hola[i];
        break;
      }
    }
  }
  for (int l = 0; l < k; l++) {
    hasilsementara = hasilsementara + temp[l];
  }
  cout << hasilsementara << endl;
  return 0;
}
