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 shuffle(a, l, r)
  first, middle, last = a[0...l-1], a[l-1..r-1], a[r..a.size]
  middle.reverse!
  middle = middle.map do |c|
    if c == 'R'
      'L'
    else
      'R'
    end
  end
  first + middle + last
end

max = 0

queue = []
queue.push([s, 0, 0])
while !queue.empty?
  s, l, r = queue.shift
  if l != 0 && r != 0
    suffled = shuffle(s, l, r)
  else
    suffled = s
  end
  num = count(suffled)
  max = num if num > max
  k -= 1
  if k >= 0
    (1..n).to_a.repeated_permutation(2) do |ll, rr|
      queue.push([suffled, ll, rr]) if ll < rr
    end
  end
end
p max
