object Main {

  def main(args: Array[String]): Unit =
    println(solve(parse(input(Array.empty))).value)

  case class Answer(value: Int)

  def solve(input: Input): Answer = {
    import input._
    val t: String = List.fill(k)(s).reduce(_ + _)
    def newChar(string: List[Char]) = ('a' to 'z').toSet.diff(string.toSet).head
    @scala.annotation.tailrec
    def f(remain: List[Char], count: Int): Int =
      remain match {
        case xs if xs.length <= 1 => count
        case _1 :: _2 :: xs if _1 == _2 =>
          f(newChar(_1 :: _2 :: xs.take(4)) :: xs, count + 1)
        case _1 :: _2 :: _3 :: xs if _1 == _3 =>
          f(_2 :: newChar(_1 :: _2 :: _3 :: xs.take(4)) :: xs, count + 1)
        case _ :: xs => f(xs, count)
      }
    Answer(f(t.toList, 0))
  }

  case class Input(s: String, k: Int)

  def parse(input: String): Input = {
    val list: List[List[String]] = input.trim.split("\n").map(_.split(" ").map(_.trim).toList).toList
    Input(list(0)(0), list(1)(0).toInt)
  }

  def input(args: Array[String]): String = {
    val sc = new java.util.Scanner(System.in)
    val a = sc.nextLine()
    val b = sc.nextLine()
    s"$a\n$b"
  }
}
