print((function (f) return f(io.stdin:read("*l"):match("%d+%s(%d+)"), io.stdin:read("*l")) end)(function (i, s) local n = 0 if s:sub(i,i) == "(" then for j=i,#s do n = s:sub(j,j) == "(" and n+1 or n-1 if n == 0 then return j end end else for j=i,1,-1 do n = s:sub(j,j) ~= "(" and n+1 or n-1 if n == 0 then return j end end end end))