unittest
{
	assert( [ "5 3", "50 100 80 120 80" ].solve == 210 );
	assert( [ "1 1", "1000" ].solve == 1000 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s"( n, k );
	input.popFront;
	auto ps = input.front.split.to!( long[] );
	
	return ps.sort().take( k ).sum;
}
