def solve(s, i)
  @s = s
  @target = i
  @i = 0
  answer = parse[i]
  return answer ? answer : "0"
end

def parse
  return "" if @i >= @s.size
  result = ""
  case @s[@i]
    when /[0-9]/
      n = number
      @i += 1 if @s[@i] == "("
      word = parse
      return word if word.size > @target
      @i += 1 if @s[@i] == ")"
      n.times do
        result += word
        return result if result.size > @target
      end
    when ")"
      return ""
    else
      result += @s[@i]
      @i += 1
  end
  result + parse
end

def number
  n = @s[@i,@s.size].to_i
  @i += Math::log10(n).to_i + 1
  n
end

until (s,i=gets.split).all?{|w|w=="0"} do
  puts solve(s, i.to_i)
end