If Ali took 6 pencils from a new box of pencils and there are 18 pencils left in the box, then there were 24 pencils in the brand new box.
To see why, you can add the number of pencils Ali took to the number of pencils left in the box:
6 + 18 = 24
Therefore, there were 24 pencils in the brand new box before Ali took 6 of them.