The ends of finitely generated groups