n,i = gets.split.map(&:to_i) s = gets.chomp stack = [] counter = 0 q = s.chars.map { |v| if v == '(' counter.incr! stack.push(counter) counter else -1 * stack.pop end } half = q[i - 1] puts q.find_index(-half) + 1