n, k = gets.split.map(&:to_i) s = gets.chomp.split(//) count = 1 case s[k-1] when '(' k.upto(n-1) do |i| count += (s[i] == '(' ? 1 : -1) if count == 0 p i+1 break end end when ')' (k-2).downto(0) do |i| count += (s[i] == ')' ? 1 : -1) if count == 0 p i+1 break end end end