Drawing the outline of the whole scene where it overlaps the sky

I need an oddly specific thing that I need to use as a mask for my post process material, the outline of the whole scene where it overlaps the sky (the background). Ideally, it shouldn’t include the parts of the objects where they overlap each other instead of the sky.
Here is a drawing over a screenshot to visualize it. (red line being the mask I need) Notice how I didn’t draw over the whole silhouette of both of the cubes in the scene, only the parts where they overlap the sky.

Any idea of drawing this would be greatly helpful!