s = gets.chomp i = gets.to_i q = s.chars.each_with_object(stack: [], parsed: [], counter: 0) { |v,o| if v == '(' o[:counter] += 1 o[:stack] << o[:counter] o[:parsed] << o[:counter] else t = o[:stack].pop o[:parsed] << t end } half = q[:parsed][i] q[:parsed][i] = 0 puts q[:parsed].find_index(half)