I want to prove the following theorem:
Let $S$ be a compact surface, and $N:S\rightarrow \Bbb{S}^2$ the Gauss map, then we have $$ \int_{S} |K| \,dA = \int_{\Bbb{S}^2} \#N^{-1} \,dA $$ where $K$ is the Gaussian curvature of the surface $S$, and $\#N^{-1}$ is the number of the preimages of the Gauss map.
I know that by the stack of record theorem and the fact that $\Bbb{S}^2$ is connected, the value $\#N^{-1}$ should be a constant locally. Also, I know that locally (within a local chart of $S$), we should have
$ \int_{U} |K| \,dA = \int_{N(U)} \,dA $
But I don't know how to prove the theorem globally by involving the number of preimages of the Gauss map. Any hints would be helpful.