# rubocop:disable all
N, K = gets.chomp.split(" ").map(&:to_i)
S = gets.chomp

h = 0
@lr = []
@rl = []
(N-1).times do |i|
  h += 1 if S[i] == S[i + 1]
  @lr << i if S[i] == "L" && S[i + 1] == "R"
  @rl << i if S[i] == "R" && S[i + 1] == "L"
end

@s = S.dup

def rotate(l, r)
  @s[l+1..r] = @s[l+1..r].reverse.split("").map{|v| v == "L" ? "R" : "L"}.join
  @lr.delete_if {|v| l < v && v < r }
  @rl.delete_if {|v| l < v && v < r }
  l.upto(r) do |i|
    @lr << i if @s[i] == "L" && @s[i + 1] == "R"
    @rl << i if @s[i] == "R" && @s[i + 1] == "L"
  end
  @lr.sort!
  @rl.sort!
end

K.times do
  r = l = nil
  # LR and RL is empty
  break if @lr.empty? && @rl.empty?

  if @lr.empty? || @rl.empty?
    h += 1
    break
  elsif @lr.size == 1
    l = @lr.shift
    if (l - @rl.first).abs == 1
      r = @rl.pop
    else
      r = @rl.shift
    end
    rotate(*[l, r].sort)
    h += r - l > 1 ? 2 : 1
  elsif @rl.size == 1
    l = @rl.shift
    if (l - @lr.first).abs == 1
      r = @lr.pop
    else
      r = @lr.shift
    end
    rotate(*[l, r].sort)
    h += r - l > 1 ? 2 : 1
  # LR..RL
  elsif @lr.first < @rl.first
    l = @lr.shift
    if @rl.first > l + 1
      r = @rl.shift
      h += 2
    elsif @rl.size > 1 && @rl[1] > l + 1
      r = @rl.delete_at(1)
      h += 2
    else
      r = @rl.shift
      h += 1
    end
    rotate(l, r)
  # RL..LR
  elsif @rl.first < @lr.first
    l = @rl.shift
    if @lr.first > l + 1
      r = @lr.shift
      h += 2
    elsif @lr.size > 1 && @lr[1] > l + 1
      r = @lr.delete_at(1)
      h += 2
    else
      r = @lr.shift
      h += 1
    end
    rotate(l, r)
  else

  end
end
puts h
