Billy brought a large box of chocolates to school. In his first class, he gave half of the chocolates in the box to his teacher. In his second class, he gave half of his remaining chocolates to his bestfriend. At lunch, he ate half of his remaining chocolates. If he had 3 pieces of chocolate left at the end of lunch, then how many pieces were in the box when Billy arrived at school?