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

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

if line_arr_length == 1 then
    print ("#{k / 2}\n")
else
    for i in 0 .. line_arr_length - 1
        if i == line_arr_length - 1
            if line_arr[i] == line_arr[0] then
                    loop do
                        if line_arr[i] != "z" then
                            line_arr[i] = line_arr[i].succ
                        else
                            line_arr[i] = "a"
                        end
        
                        if line_arr[i] != line_arr[i - 1] then
                            break
                        end
                    end
                    counter += 1
                    flug = 1
            end
            
        elsif 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 * k - flug}\n")
end