nn, kk = gets.split.map(&:to_i)
ss = gets.chomp

if nn==1
  puts 0
  exit
end

sum = 0
prev = 'R'
c1 = ss[0]=='R' ? 'R' : 'L'
c2 = ss[0]=='R' ? 'L' : 'R'

# 最後以外カウント
0.upto(nn-2) do |n|
  if ss[n]=='R' && ss[n+1]=='R'
    sum+=1
  elsif ss[n]=='L' && prev=='L'
    sum+=1
  end
  prev = ss[n]
end
# 最後
if ss[-1]=='L' && ss[-2]=='L'
  sum+=1
end

#RLの数
cnt = ss.scan(/#{c1}#{c2}/).size

#補正
edge_cnt = 0
if ss[0]=='R'
  if ss[-1]=='L'
    cnt-=1
    edge_cnt+=1
  end
else #ss[0]=L
  if ss[-1]=='R'
    cnt-=1
    edge_cnt+=1
  end
end
inc = 0

if cnt >= kk
  inc = kk*2
else
  kk -= cnt
  inc = cnt * 2 + [kk,edge_cnt].min
end
puts sum + inc
