From the spectrum to inflation: an inverse formula for the general slow-roll spectrum