The simplest proof consists in noting that , where (called an indicator function) is a random variable that equals 1 if and 0 else. This is just because the first indicator functions equal 1 and the others equal 0.

Then, by monotone convergence theorem and linearity of the expectation, , and as you can check (you integrate 1 when and 0 else...). So this is it.