Ivan had cookies and Ethan had croissants. Both gave half of what they had to each other. Ivan sold 9 cookies and Ethan sold 23 croissants. In the end, the ratios of cookies to croissants for Ivan and Ethan were 1 : 5 and 1 : 3 respectively. How many cookies did Ivan have at first?