#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int sum = 0, min = 1001, max = 0;
  if (n - k > k) {
    while (k != 0) {
      for (int i = 0; i < n; i++) {
        if (min > arr[i]) {
          min = arr[i];
        }
      }
      sum += min;
      for (int i = 0; i < n; i++) {
        if (min == arr[i]) {
          arr[i] = 1001;
          break;
        }
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (max < arr[i]) {
        max = arr[i];
      }
    }
    sum += max;
    for (int i = 0; i < n; i++) {
      if (max == arr[i]) {
        arr[i] = 0;
        break;
      }
    }
  }
  cout << sum;
}
