Alex bought a bag of apples on Saturday,

and he ate a third of them.

On Sunday he ate half of the remaining apples.

He ate one more on Monday and one more on Tuesday,

and then ate half of the remaining apples on Wednesday.

On Thursday he looked in the bag and saw that there was just one apple left.

How many apples did the bag have to begin with?