#include <bits/stdc++.h>
int main() {
  int n, k, p[1001], q[1001], count = 0;
  scanf("%d %d", &n, &k);
  scanf("%d", &p[0]);
  q[0] = p[0];
  for (int i = 1; i < n; i++) {
    scanf("%d", &p[i]);
    q[i] = p[i];
    if (p[i] < q[i - 1]) {
      q[i] = q[i - 1];
      q[i - 1] = p[i];
    } else {
      q[i] = p[i];
    }
  }
  for (int i = 0; i < k; i++) {
    count = count + q[i];
  }
  printf("%d\n", count);
}
