A salesman bought backpacks for $576. He sold 17 of them for $18 each to a trailer, and the rest were sold to a department store for $25 each. How much was the salesman’s profit? How much money did he gain?