N, K = gets.chomp.split.map(&:to_i)
S = gets.chomp.chars
# A, B, C = gets.chomp.split.map(&:to_i)

# TODO(south37) Fix this
init_val = 0
# Count R
0.upto(N-2).each do |i|
  if (S[i] == 'R') && (S[i+1] == 'R')
    init_val += 1
  end
end
# Count L
(N-1).downto(1).each do |i|
  if (S[i] == 'L') && (S[i-1] == 'L')
    init_val += 1
  end
end

rls = []
0.upto(N-2).each do |i|  # Check RL
  if (S[i] == 'R') && (S[i+1] == 'L')
    rls << i
  end
end
lrs = []
0.upto(N-2).each do |i|  # Check LR
  if (S[i] == 'L') && (S[i+1] == 'R')
    lrs << i
  end
end

# p rls
# p lrs

if (K <= lrs.size) && (K <= rls.size)
  r = init_val + 2 * K
else
  # lrs or rls is smaller than K
  if lrs.size == rls.size
    r = init_val + 2 * lrs.size
  else
    min_len = [lrs.size, rls.size].min
    r = init_val + 2 * min_len + 1
  end
end

p r