A chef had 40 apples and 54 peaches. After making some pies, he had 39 apples left. How many apples did he use?