Detect highest block above player

Trying to make a /top like command with a datapack, where the player will tp to the highest block above them. How would you detect the highest block above a player and if there even is one in the first place?

Continue to help post