s = gets
k = gets.to_i

ls = s.split("")
len = ls.length*k

cnt = 0
i = 0
a=ls[0]
while i<len-1
  b=ls[(i+1)%ls.length]
  if a==b then
    cnt += 1
    a=i
  else
    a=ls[(i+1)%ls.length]
  end
  i += 1
end
print(cnt)