n,k = gets.to_s.split.map(&:to_i)
s = gets.to_s.chomp.split("")
count = 0
beforeLr = ""
s.each do |lr|
  if beforeLr == lr
    count += 1
    if k > 0
      count += 2
      k -= 1
    end
  end
  if count > s.length - 1
    count = s.length - 1
  end
  beforeLr = lr
end
puts count