input_lines = readlines

s = input_lines[0].to_s.chomp
K = input_lines[1].to_i

at = s.split("")

len_cnt = (s.length * K) - 1
replace_cnt = 0

rnd_chr = ("a".."z").to_a
r = rnd_chr.sample(1).join

for i in 1..len_cnt do
  as = s.split("")
  at.concat(as)

  target = at[i]

  while !(r != at[i-1] && r != at[i+1]) do
    r = rnd_chr.sample(1).join
  end
  
  if target.eql?(at[i-1])
    replace_cnt = replace_cnt + 1
    target.replace(r)
  end
end

p replace_cnt
