/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
6 1
LRLRRL
---+/
/+---test
13 3
LRRLRLRRLRLLR
---+/
/+---test
10 1
LLLLLRRRRR
---+/
/+---test
9 2
RRRLRLRLL
---+/

void main(string[] args) {
  long N, K;
  readf(" %d %d ", &N, &K);
  auto S = ['R']~readln.chomp.to!(char[])~"L";

  size_t happy_count;
  foreach (i; 1..S.length-1) {
    happy_count +=
      (S[i] == 'L' && S[i-1] == 'L') ||
      (S[i] == 'R' && S[i+1] == 'R');
  }

  bool to_reverse;
  char pc;
  foreach (i, c; S) {
    if (K  <= 0) break;
    if (pc == c) continue;

    if (to_reverse) {
      happy_count += 2;
      --K;
      to_reverse = false;
    }
    to_reverse = i > 1 && c == 'L';
    pc = c;
  }
  if (K > 0 && to_reverse) {
    --K;
    ++happy_count;
  }
  if (K > 0 && S[0] == 'L') {
    --K;
    ++happy_count;
  }

  happy_count.writeln;
}
