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!
  first + middle + last
end

max = count(s)

k.times do |i|
  (1..n).to_a.combination(2) do |l, r|
    s = shuffle(s, l, r)
    num = count(s)
    max = num if num > max
  end
end
p max
