s = gets.chomp!.to_s
k = gets.chomp!.to_i

s = s * k

p = 0
count = 0

ls = s.split("")
#p ls

def check(ls, p, count)
  if p >= ls.length
    return count
  end
  if ls[p] == ls[p+1]
    p += 2
    count += 1
    check(ls, p, count)
  else
    p += 1
    check(ls, p, count)
  end

end


p check(ls, p, count)