input = gets.chomp
a = input.split(' ')
n = a[0].to_i
k = a[1].to_i
s = gets.chomp

# Kが1回前提
d_max_score = 0

for d in 1..k
  for l in 1...n
    for r in l...n
      # p s[l..r], [l,r]
      moved = s.dup
      for z in l..r
        if s[z] == 'L'
          moved[z] = 'R'
        elsif s[z] == 'R'
          moved[z] = 'L'
        end
      end
      ### p [l, r]
      ### p s.dup
      # p moved
      # score 計算
      score = 0
      prev = nil
      for i in 1...moved.size
        if moved[i - 1] == moved[i]
          score += 1
        end

        prev = moved[i]
      end

      if d_max_score < score
        d_max_score = score
      end
    end
  end
end
p d_max_score