o,k = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp.chars

hp = 0
sw = true
s.inject do |i,j|
  if i == j
    hp += 1
  else
    if 0 < k
      if sw
        sw = false
      else
        sw = true
        k -= 1
        hp += 2
      end
    end
  end
  j
end
unless sw
  if 0 < k
    hp += 1
  end
end
print("#{hp}")