target = gets.chomp
count = gets.to_i

def num_duplicate_char(target)
  ary = target.split(//)
  prev = ary.last
  count = 0
  last_index = ary.size - 1
  changed_prev = false
  ary.each.with_index do |ch, index|
    if ch == prev
      if index != last_index
        if changed_prev
          changed_prev = false
        else
          count += 1
          changed_prev = true
        end
      end
    end

    prev = ch
  end
  count
end

puts num_duplicate_char(target) * count