local n, k = io.read("*n", "*n", "*l")
local s = io.read()
local prv = s:sub(1, 1)
local nxt = ""
local changed = 0
local score = 0
for i = 2, n do
  nxt = s:sub(i, i)
  if prv == nxt then
    score = score + 1
  else
    changed = changed + 1
  end
  prv = nxt
end
while 0 < changed and 0 < k do
  if 2 <= changed then
    changed = changed - 2
    k = k - 1
    score = score + 2
  else
    changed = changed - 1
    k = k - 1
    score = score + 1
  end
end
print(score)
