RNA secondary structure: a complete mathematical analysis