How to show that $f$ is surjective? Suppose that $f:M\to N$ is an immersion between smooth manifolds $M$ and $N$ of the same dimension where $M$ is compact and $N$ is connected. How to show that $f$ is surjective?

You can show that $f(M)$ is both open and closed in $N$. Since $N$ is connected, this implies that $f(M)=N$.
Let's first check that $f(M)\subset N$ is closed. Since $M$ is compact and $f$ is continuous, also $f(M)\subset N$ is compact. Since $N$ is Hausdorff, this implies that $f(M)\subset N$ is closed.
Next, we check that $f(M)\subset N$ is open. Choose a point $f(p)\in f(M)$. Since $f$ is an immersion and $\dim(M)=\dim(N)$, the differential $(df)_{p}$ is an isomorphism. By the inverse function theorem, there is an open neighborhood $U$ of $p$ such that $f(U)$ is an open neighborhod of $f(p)$. Since $f(U)$ is contained in $f(M)$, this shows that $f(M)\subset N$ is open.
