Go through all the obstacles. When you reach the flag, jump over it, wait for the ghost to pass, then move back to the flag and touch it. A video walkthrough may help: game-solver.com/cat-mario-walkthrough/