Answer
$\frac{1}{2}Mg(\sqrt {L^{2}+D^{2}}-L)$
Work Step by Step
Please see the attached image first,
By using the principle of Pythagoras,
$AB^{2}=L^{2}+D^{2}$
$AB=\sqrt {L^{2}+D^{2}}-(1)$
Energy provided $(E)=$Final potential energy - Initial potential energy
$E=Mg\frac{(AB)}{2}-Mg\frac{L}{2}$
$(1)=\gt$
$E=\frac{Mg}{2}(\sqrt {L^{2}+D^{2}}-\frac{MgL}{2})$
$E=\frac{1}{2}Mg(\sqrt {L^{2}+D^{2}}-L)$
The energy needed to bring the pipe $=E=\frac{1}{2}Mg(\sqrt {L^{2}+D^{2}}-L)$
to the adjacent unstable equilibrium