#set
s = gets.chomp
k = gets.chomp.to_i
# char_list_arr = [a-z]

#main
line = s * k
line_arr = line.chomp.split("")
line_arr_length = line_arr.length
counter = 0

for i in 0 .. line_arr_length - 2
    if i == line_arr_length -2 then
        if line_arr[i] == line_arr[i + 1] || line_arr[i + 1] == line_arr[0] then
            loop do
                if line_arr[i + 1] != "z" then
                    line_arr[i + 1] = line_arr[i + 1].succ
                else
                    line_arr[i + 1] = "a"
                end

                if line_arr[i + 1] != line_arr[0] then
                    break
                end
            end
            counter += 1
        end
    else
        if line_arr[i] == line_arr[i + 1] then
            loop do
                if line_arr[i + 1] != "z" then
                    line_arr[i + 1] = line_arr[i + 1].succ
                else
                    line_arr[i + 1] = "a"
                end

                if line_arr[i + 1] != line_arr[i + 2] then
                    break
                end
            end
            counter += 1
        end
    end
end

print ("#{counter}\n")