Solution (source code)

= Solution

Conditional on $X_0=x$, the random variable $T$ is the <first return time> $T_x^+$. The <Kac's lemma> mean-recurrence formula for a finite <irreducible Markov chain> gives
$$
\mathbb E_xT_x^+=\frac1{\pi(x)}.
$$
Averaging over $X_0\sim\pi$ therefore yields
$$
\boxed{\mathbb E[T]=\sum_x\pi(x)\frac1{\pi(x)}=N}.
$$