def change_count (array, multiple)
  chars = array * multiple
  change_count = 0
  (1...chars.size).each do |i|
    if chars[i - 1] == chars[i]
      chars[i] = 'A'
      change_count += 1
    end
  end
  change_count
end

INF = 10 ** 9
s = gets.chomp.split("")
k = gets.to_i
first_change_count = change_count(s, 1)
cycle = []
(2..INF).each do |i|
  increment_change_count = change_count(s, i) - (first_change_count + cycle.sum)
  break if cycle.first == increment_change_count
  cycle << increment_change_count
end

ans = first_change_count
k -= 1

div, mod = k.divmod(cycle.size)
ans += cycle.sum * div
ans += cycle[0...mod].sum

puts ans
