Let $\pi:X\times M \to M$ be the projection.

Theorem 9.11 in Atiyah-Bott's "The Yang-Mills Equations over Riemann Surfaces" states that $c_1(\mathcal{U}_x)$ and $c_1(R\pi_*\mathcal{U})$ generate the second cohomology group (knowing that $M$ is simply connected). This is true an arbitrary choice of $\mathcal{U}$. By Grothendieck-Riemann-Roch, we know that
$$c_1(R\pi_*\mathcal{U}) = (1-g)c_1(\mathcal{U}_x) + \pi_*\operatorname{ch}_2(\mathcal{U}) .$$
It follows that an alternative set of generators for the integral second cohomology is given by $c_1(\mathcal{U}_x)$ and $\pi_*\operatorname{ch}_2(\mathcal{U})$.

Note that tensoring $\mathcal{U}$ by $\pi^*H$ for a line bundle $H$ on $M$ changes $c_1(\mathcal{U})$ by $rc_1(H)$, and that
$$\pi_*\operatorname{ch}_2(\mathcal{U}\otimes \pi^*H) =\pi_*\operatorname{ch}_2(\mathcal{U})+d c_1(H)$$

Now choose integers $a,b$ satisfying $ar - b d = 1$, and pick $H$ satisfying $c_1(H) = \pi_*\operatorname{ch}_2(\mathcal{U})$. Let $\mathcal{U'}:=\mathcal{U}\otimes \pi^*H$.
Then $\pi_*\operatorname{ch}_2(\mathcal{U}')$ is divisible by $r$, but generates the second cohomology together with $c_1(\mathcal{U}'_x)$. Therefore, the latter must be coprime to $r$, in particular this is true for $c_1(\mathcal{U})$.