Put any number of target creature cards from your graveyard on top of your library.
Draw a card.
You can cast Gravepurge with no targets. If you do, you’ll just draw a card. However, if you cast it with at least one target and all of those targets become illegal, the spell won’t resolve and you won’t draw a card.
If you cast Gravepurge with at least one target and all of those targets become illegal, the spell won’t resolve and you won’t get to draw a card.
You can cast Gravepurge with zero targets. If you do, you’ll draw a card as the spell resolves.
You choose the order of the cards you put on top of your library.