#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  scanf("%d", &N);
  int K;
  scanf("%d", &K);
  int p[N];
  for (int i = 0; i < N; ++i) {
    scanf("%d", &p[i]);
  }
  sort(p, p + (sizeof(p) / sizeof(p[0])));
  switch (K) {
    case 1:
      cout << p[0];
      break;
    case 2:
      cout << p[0] + p[1];
      break;
    default:
      cout << p[0] + p[1] + p[2];
      break;
  }
  cout << "\n";
  return 0;
}
