solve the valid parenthess