$f(n)=n-2$ works as I said in the comment above. On the other hand, $f(n) < n-1$ for $n\ge 4$. Indeed, the metabelian Baumslag-Solitar group can be given by relations $\langle x_1,...,x_{n-1},u,v,t\mid x_1=x_2, x_2=x_3, ..., x_{n-2}=x_{n-1}, tx_1=u, ut^{-1}=v, x_1^2=v\rangle $ with $n+2$ generators and $n+1$ relations. So the answer is $f(n)=n-2$ - for every $n\ge 2$$n\ge 4$.