Gap theorems for noncompact Riemannian manifolds