s = gets.chomp
k = gets.to_i

temp = 0
(0..s.size-1).each do |i|
  if s[i] != '*' && s[i] == s[i+1] 
    temp += 1
    s[i+1] = '*'
  end
end

if k == 1
  puts temp
  exit
end

if s[0] == s[s.size-1]
  puts temp * k + k - 1
else
  puts temp * k
end