Heteroatom-doped carbon materials with interconnected channels as ultrastable anodes for lithium/sodium ion batteries.