Spectral method for ill-posed problems based on the balancing principle