Let \(g=(a,m)\). If \(ax ≡ b \bmod m\), then:
$$\begin{gather} ax = b + mk \text{ where } k \in \mathbb{Z} \\ ax - mk = b \end{gather}$$
If \(g\) is the greatest common divisor of \(a\) and \(m\), then \(g\) can divide any linear combination of \(a\) and \(m\) (including \(b\)) (proof). However, if \(g \nmid b\), then there is no valid value of \(x\) and \(k\), such that \(ax - mk = b\).