#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, n, p[n];
  cin >> n >> k;
  int u = 0;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    if (i = 0)
      continue;
    else {
      if (p[i] < p[i - 1]) {
        u = p[i];
        p[i] = p[i + 1];
        p[i + 1] = u;
      } else if (p[i] == p[i - 1])
        continue;
    }
  }
  int ans = 0;
  for (int i = 0; i < k; i++) ans += p[i];
  return 0;
}
