At first, Sam had some money. He spent 13 of it on a coat and 23 of the remainder on a shirt. After that, his uncle gave him $360. The ratio of the total amount of money he had in the end to the amount of money he had at first was 4 : 3. How much money did Sam have at first?