A local bakery sells cupcakes for $3 each and cookies for $2 each. On a sunny Saturday, they sold a total of 40 items, which were either cupcakes or cookies. If the total revenue from the sales was $108, how many cupcakes did the bakery sell?