Diffuse Gamma-Ray Emission from Starburst Galaxies and M31