The Time-averaged Mass-loss Rates of Red Supergiants as Revealed by Their Luminosity Functions in M31 and M33