Considering the standard geometric coin toss, let $N$ be the number of tosses until the first heads appears. The probability of getting heads is $p$. I understand how to find $E[N]$ by conditioning on the value of the first toss, but I'm having a hard time generalizing this process to a function of a random variable. I know how to get the answer $\frac{2-p}{p^2}$ using sums but I can't figure out how to do it using conditional expectation.
For $E[N]$, I let $Y=0$ is tails on the first toss and $Y=1$ if heads. Then $E[N|Y=1]=1$ and $E[N|Y=0]=1+E[N]$ which gives that $E[N]=E[E[N|Y]]=\frac{1}{p}$. What do I do to find $E[N^2]$ this way?