Synthesis of hetero- and carbocycles by nucleophilic substitution at sp2 carbon