n,k = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp.split("").map{|c| c == "L" ? -1 : 1}

k.times do
  flag = true
  lr = s[0]
  (0..s.length-1).each do |i|
    next if s[i] == lr
    s[i] = lr
    flag = false
    (i+1..s.length-1).each do |j|
      if s[j] == lr then
        break
      else
        s[j] = lr
      end
    end
    break
  end
  break if flag
end

count = 0
s.each_cons(2) do |c1, c2|
  count += 1 if c1 == c2
end
puts count
