Magnetization of carbonaceous asteroids by nebular fields and the origin of CM chondrites