#include <bits/stdc++.h>
void swap(int *a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}
void quickSort(int a[], int left, int right) {
  int pivot;
  int i, j;
  if (left >= right) return;
  pivot = a[left];
  i = left;
  j = right;
  while (1) {
    while (a[i] < pivot) i++;
    while (a[j] > pivot) j--;
    if (i >= j) break;
    swap(&a[i], &a[j]);
    i++;
    j--;
  }
  quickSort(a, left, i - 1);
  quickSort(a, j + 1, right);
}
int main() {
  int N, K, ans = 0;
  scanf("%d %d", &N, &K);
  int *p = (int *)malloc(sizeof(int) * N);
  quickSort(p, 0, N - 1);
  for (int i = 0; i < K; i++) {
    ans += p[i];
  }
  printf("%d\n", ans);
  return 0;
}
