A catalyst-controlled selective synthesis of pyridines and pyrroles