Chip-firing and energy minimization on M-matrices