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

max = count(s)
k.times do
  max += 2 if max < n - 2
  max += 1 if max == n - 2
  break if max == n - 1
end
p max
