Magnetic properties of weakly coupled superconducting grains