unittest
{
	assert( [ "6 1", "LRLRRL" ].parse.expand.solve == 3 );
	assert( [ "13 3", "LRRLRLRRLRLLR" ].parse.expand.solve == 9 );
	assert( [ "10 1", "LLLLLRRRRR" ].parse.expand.solve == 9 );
	assert( [ "9 2", "RRRLRLRLL" ].parse.expand.solve == 7 );
	
	assert( [ "4 2", "RRRR" ].parse.expand.solve == 3 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
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 s = input.front.to!( dchar[] );
	return tuple( nk[ 1 ], s );
}

auto solve( long k, dchar[] s )
{
	auto gs = s.group.array;
	auto ans = 0L;
	if( gs.length == 1 )
	{
		ans = gs.front[ 1 ] - 1;
	}
	else
	{
		foreach( i, g; gs[ 1 .. $ - 1 ] )
		{
			if( i % 2 == 0 && 0 < k )
			{
				ans += g[ 1 ] + 1;
				k--;
			}
			else
			{
				ans += g[ 1 ] - 1;
			}
		}
		if( 0 < k ) ans += gs.front[ 1 ];
		else        ans += gs.front[ 1 ] - 1;
		if( 1 < k ) ans += gs.back[ 1 ];
		else        ans += gs.back[ 1 ] - 1;
	}
	return ans;
}
