# Number of poles and zeros

I'm having a trouble with this question -- say we have some region $M$ , where $f$ is holomorphic except at finitely many poles, and $f$ is continuous on the closure of $M$. If $\mathrm{Im} f(z)\neq 0$ on the boundary of $M$, then the number of poles in $M$ equals the number of zeroes.

I'm having a difficulty approaching this question. I've tried using argument principle, by writing out $f(z)=(z-z_o)^ng(z)$ and doing the same for the poles and integrating the derivative of this function divided the function itself, but I see no connection with the fact that imaginary part is non-zero on the boundary....

You are right that the argument principle is the key here, but it must be viewed geometrically. The argument principle says that $$\frac{1}{2\pi i}\int_{\partial M}\frac{f'}{f} = Z - P,$$ where $Z$ is the number of zeros of $f$ inside $M$ and $P$ is the number of poles inside $M$. Stated geometrically, it says that $$\frac{1}{2\pi i}\int_{\partial M}\frac{f'}{f} = \omega(f(\partial M);0),$$ where $\omega(\gamma, z_0)$ denotes the winding number of a closed contour $\gamma$ around the point $z_0$. From these two statements of the argument principle we see that $$Z - P = \omega(f(\partial M);0).$$
Now to solve your problem, note that since $\textrm{Im}(f(z)) \neq 0$ on $\partial M$, i.e. $f(\partial M)$ never crosses the real axis, we have $$\omega(f(\partial M);0) = 0.$$
Note that the statement is also true if we instead suppose that $\textrm{Re}(f(z)) \neq 0$ on $\partial M$, or if more generally we suppose that $\textrm{Arg}(f(z)) \neq \theta$ for some fixed $\theta \in [0,2\pi)$.