The condensation of 1-methyl-4-piperidone (I) with ethyl cyanoacetate (II) in refluxing acetic acid gives ethyl (1-methyl-4-piperidylidene)cyanoacetate (III), which by reaction with KCN in ethanol is converted to ethyl (1-methyl-4-cyano-4-piperidyl)cyanoacetate (IV). The decarboxylative hydrolysis of (IV) with refluxing aqueous HCl affords (1-methyl-4-carboxy-4-piperidyl)acetic acid (V), which is esterified with ethanol - HCl to its diethyl ester (VI). Finally, this compound is treated with ethylamine at 200 C.