Distances to spaces of measurable and integrable functions