n,k = gets.split.map(&:to_i)

s = gets.chomp.each_char.map{|c|c=="L"}
#Lがtrue,Rがfalse

happy = 0
tgl = 0
prev = s[0]
s[1..-1].each{|x|
  if prev==x
    happy += 1
  else
    tgl += 1
  end
  prev = x
}

p [happy+[tgl,k].min*2, n-1].min