A farmer bought a number of pigs for $160. However, 8 of them died before he could sell the rest at a profit of 6 per pig. His total profit was $8. How many pigs did he originally buy?