Theory of magnetic impurities in superconductors. I