Quinton brought 40 cupcakes to school on his birthday. He gave a cupcake to each of the 18 students in Ms. Delmonts class. He also gave a cupcake to each of the 16 students in Mrs Donnelly's class. He also gave a cupcake to Ms. Dolmont, Mrs Donnelly, the school nurse and the school principal. How many cupcakes did he have left over?