David decided it was time to get rid of a bunch of books that he had outgrown. He started out by giving half the books to his younger cousin. Of the books that were left, one-eighth of them were about trains, so he gave those to the little girl next door who loves trains. Of the books that were left, he gave one-fourth of them to his little brother. He sold two-thirds of the ones that were left at a yard sale. Then he donated the last seven books to charity. How many books did David decide to get rid of before he gave any away?