Determining the optimal level of media spending