This is indeed a consequence of Krull's Hauptidealsatz, but what you tried to prove is not true in general.
To prove the formula, we'll show that, for any chain $\mathfrak p_0\subset\dots\subset\mathfrak p_n=\mathfrak m$ of prime ideals, there exists another chain
$$\mathfrak p'_0\subset\dots\subset\mathfrak p'_n=\mathfrak m,\enspace\text{such that}\enspace f\in\mathfrak p'_1.$$
We prove this by induction on $n$. If $n=1$, there's nothing to prove. So suppose $n\ge 2$.
- If $f\in\mathfrak p_{n-1}$, localising $A$ at $\mathfrak p_{n-1}$, we obtain a chain of prime ideals of length $n-1$ in $A_{\mathfrak p_{n-1}}$ satisfying the above condition, by the inductive hypothesis. This chain corresponds to a chain in $A$, which we complete with $\mathfrak m$ to obtain a chain of length $n$ such that $f\in\mathfrak p'_1$.
- If $x\notin\mathfrak p_{n-1}$, let $\mathfrak p'_{n-1}$ an element which is minimal among the prime ideals which contain $\mathfrak p_{n-2}+Af$. By the Hauptidealsatz, the ideal $\mathfrak p'_{n-1}/\mathfrak p_{n-2}\subset A/\mathfrak p_{n-2}$ has height $1$, hence $\mathfrak p_{n-2}\subset \mathfrak p'_{n-1}\subset \mathfrak m$ is a chain of length $2$. Thus we've come down to the previous case – a chain:
$$\mathfrak p_0\subset\dots\subset\mathfrak p_{n-2}\subset \mathfrak p'_{n-1}\subset \mathfrak p_n=\mathfrak m,\enspace\text{such that}\enspace f\in\mathfrak p'_{n-1}.$$