Phase transition in a system of magnetic impurities