As a tadpole matures, it changes by gradually growing limbs, usually the back legs first. Then it gradually loses its tail by programmed cell death (apoptosis). Lungs develop at the time of leg development: tadpoles late in development are often near the surface of the water, where they breathe air. During the final stages, the tadpole's mouth changes from a small mouth at the front of the head to a large mouth the same width as the head. The intestines shorten to accommodate the new diet. Most tadpoles are herbivorous, living on algae and plants. Some species are omnivorous, eating detritus and, when available, smaller tadpoles.