At first, Dylan had some money. He spent 14 of it on a coat and 27 of the remainder on a dress. After that, his aunt gave him $240. The ratio of the total amount of money he had in the end to the amount of money he had at first was 5 : 4. How much money did Dylan have at first?