The primary function of the alveoli in the lungs is: