
n=gets.chomp.split("").map(&:to_s)
v=n[0]
n.push(v)
#p n
t=gets.to_i
i=1
count=0
count
count_zero=0
while i<=n.length-1
    #p i
    if i==n.length-1 && n[i-1]==n[i]
        n[i]="#"
             count_zero=1
             i+=1
             next
    elsif n[i-1]==n[i]
        n[i]="#"
        count+=1
        i+=1
        next
   
    end
    i+=1
end

p count*t+count_zero*(t-1)