import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array, std.functional;

int happiness(string s) {
  int r = 0;
  foreach(i; 0..s.length) {
    if (s[i] == 'L' && i != 0 && s[i-1] == 'L') r++;
    if (s[i] == 'R' && i != s.length - 1 && s[i+1] == 'R') r++;
  }
  return r;
}

string inverse(string s, int l, int r) {
  assert(l<=r);
  char[] res = s.dup;
  foreach(i; 0..(r-l+1)) {
    if(s[l+i] == 'L') res[r-i] = 'R';
    if(s[l+i] == 'R') res[r-i] = 'L';
  }
  return cast(string)res;
}

void main() {
  auto input = readln.split.to!(int[]);
  auto N = input[0], K = input[1];
  auto S = readln.split[0];

  auto h = happiness(S);
  auto num = 1;
  foreach(i; 1..S.length) {
    if(S[i] != S[i-1]) num++;
  }

  while(K > 0 && num >= 3) {
    K--;
    num-=2;
    h+=2;
  }
  if(K > 0 && num == 2) {
    K--;
    num--;
    h++;
  }
  h.writeln;
}
