Consider a small element dx of the rod at a distance x from the left end of the rod.
Mass of this small element is dM=MLdx,
Distance of this small element from mass m is x+h
Force on m due to this small element is dF=GmdM(x+h)2
To get the total force F on the mass m, we integrate dF from x=0 to x=L
So, the force on m due to homogeneous bas is =GMmh(L+h).