Solution (source code)

= Solution

For a generic target value $y\in\mathbb{CP}^1$, its finite preimages solve
$$
P(z)-yQ(z)=0.
$$
When $m\ne n$ this has $\max(m,n)$ roots after the missing roots or poles at infinity are counted; when $m=n$, a generic $y$ again gives degree $m$. Holomorphic maps preserve orientation at regular preimages, so every local sign is positive. Hence
$$
\boxed{\deg f=\max(m,n)}.
$$