unittest
{
	assert( [ "5 2", "1 1 2 2 5" ].parse.expand.solve == 1 );
	assert( [ "4 4", "1 1 2 2" ].parse.expand.solve == 0 );
	assert( [ "10 3", "5 1 3 2 4 1 1 2 3 4" ].parse.expand.solve == 3 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

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

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( nk[ 1 ], as );
}

auto solve( long k, long[] as )
{
	as.sort();
	auto gs = as.group.map!( ( a ) => a[ 1 ] ).array;
	
	if( gs.length <= k ) return 0;
	
	gs.sort();
	auto ds = gs.take( gs.length - k );
	
	return ds.sum;
}
