Take the infinitesimal dy at the coordinate y, and the infinitesimal mass dm=(m/L)dy.
Trace element gravitational potential energy? DV= dmgy= (mg/l) ydy
What about the whole gravitational potential energy chain?
V=∫dV=(mg/L)∫ydy?
Substitute the upper limit of integral l? Is the lower limit 0 integral available? V=mgL/2