require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end
# N = gets_i

# 入力値を文字列で返却する
def gets_s()
  gets.chomp
end
# S = gets_s

# 入力値を文字の配列で返却する
def gets_nsp_list()
  gets.chomp.split("")
end

s_list = gets_nsp_list
K = gets_i

count = 0
target_poss = []

1.upto(s_list.size - 1) do |i|
  if s_list[i] != "#" && s_list[i-1] == s_list[i]
    s_list[i] = "#"
    count += 1
    target_poss << i
  end
end

if K > 1 && s_list.first == s_list.last && !target_poss.include?(s_list.size - 1)
  count += 1
end

puts count * K