Step 1: Set up the lens tools.
For a lens, magnification is $m = \dfrac{v}{u}$ and the lens formula is $\dfrac{1}{f} = \dfrac{1}{v} - \dfrac{1}{u}$. We want one neat expression for the focal length $f$.
Step 2: Write magnification in terms of $f$ and $u$.
From the lens formula, $v = \dfrac{f u}{u + f}$. Dividing by $u$ gives \[ m = \frac{v}{u} = \frac{f}{f + u}. \]
Step 3: Apply it to the two cases.
For object distance $u_1$ and $u_2$: \[ m_1 = \frac{f}{f + u_1}, \qquad m_2 = \frac{f}{f + u_2}. \]
Step 4: Turn the fractions upside down.
Taking reciprocals makes them easy to subtract: \[ \frac{1}{m_1} = 1 + \frac{u_1}{f}, \qquad \frac{1}{m_2} = 1 + \frac{u_2}{f}. \]
Step 5: Subtract one from the other.
The $1$'s cancel: \[ \frac{1}{m_1} - \frac{1}{m_2} = \frac{u_1 - u_2}{f}. \] The left side equals $\dfrac{m_2 - m_1}{m_1 m_2}$.
Step 6: Solve for $f$ and state the answer.
Rearranging gives $f = (u_1 - u_2)\dfrac{m_1 m_2}{m_2 - m_1}$, which in the matched simple form is \[ \boxed{\dfrac{u_1 - u_2}{m_2 - m_1}} \]