n,k = gets.split.map(&:to_i)
face = gets.chomp.split("")
happy = 0
count = 0
for i in 1..n-1
  if face[i] == face[i-1]
    happy += 1
  else
    count += 1
  end
end
if count == 1
  happy += 1
else
  if face[0] != face[1]
    count -= 1
  end
  if face[-1] != face[-2]
    count -= 1
  end
  if k*2 < (count / 2)*2
    happy += k*2
  elsif k*2 >= (count / 2)*2 && k < (count / 2)*2
    happy += (count / 2)*2
  else
    happy += count
  end
end
puts happy
