A teacher bought 32 packets of pencils. 17 of the packets had 8 pencils and the other packets had 14 pencils in each. How many pencils did the teacher buy in all?