n,k = gets.split.map(&:to_i)
face = gets.chomp.split("")
happy = 0
count = 0
for i in 1..n-1
  if face[i] == face[i-1]
    happy += 1
  else
    count += 1
  end
end
min = 1
max = 2
for i in 1..k
  for j in min..n-1
    if face[j-1] != face[j]
      min = j
      break
    end
  end
  for j in max..n
    if face[-j+1] != face[-j]
      max = j
      break
    end
  end
  if min > n-max
    break
  elsif min == n-max
    happy += 1
    break
  end
  happy += 2
  min += 1
  max += 1
end
if count == 1
  happy += 1
end
puts happy
