We analyze a possibility of gain-induced compensation of losses in a one-dimensional layered structure, consisting of alternating layers of metal and dielectric with gain. Using an exact approach without effective medium approximations, we demonstrate that losses can be completely compensated for a certain value of the longitudinal component of the wave vector and partially reduced for other wave numbers. In the systems with larger values of the gain coefficient, convective instabilities can appear. At certain frequencies, losses can be greatly reduced for a broad range of the incidence angles. We find that in the canalization regime when the isofrequency contours are close to straight lines, the loss compensation becomes possible for a wide spatial spectrum being useful for improvement of the subwavelength imaging capability.