#include <iostream>
using namespace std;
int main()
{
	int K, N;
	cin >> N >> K;
	int p[1001];
	for (int i = 0; i < N; i++)
	{
		cin >> p[i];
	}
	int minm = p[0], index = 0, sum = 0;
	for (int i = 0; i < K; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (minm > p[j] && p[j] !='\0')
			{
				minm = p[j];
				index = j;
			}
		}
		sum += minm;
		p [index] = '\0';
		for (int j = 0; j < N; j++)
		{
			if (p[j] != '\0')
			{
				minm = p[j];
				break;
			}
		}
	}
	cout << sum << endl;
