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

def count(a)
  sum = 0
  asize = a.size
  asize.times do |i|
    sum += 1 if (a[i] == 'L' && i != 0 && a[i - 1] == 'L') || (a[i] == 'R' && i != asize - 1 && a[i + 1] == 'R')
  end
  sum
end

def count_reverse(a)
  sum = 0
  (a.size - 1).times do |i|
    sum += 1 if a[i] != a[i + 1]
  end
  sum
end

reverse = count_reverse(s)

max = count(s)
k.times do
  reverse -= 2 if reverse >= 2
  reverse -= 1 if reverse == 1
  break if reverse == 0
end
p n - reverse - 1

