function Main(arg) {

    var K = arg.split("\n")[0];
    var S = arg.split("\n")[1]-0;

    var T = K + K[0];

    var ans = 0;
    var f = false;
    for (var i = 1; i < T.length; i++){
        if (T[i - 1] === T[i]) {
            var tmp = T.slice(0, i) + "*" + T.slice(i + 1, T.length);
            T = tmp;
            ans++;
            if (i === T.length - 1) f = true;
        }
    }
        
    console.log(f ? ans*S-1 : ans*S);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));