A doped amorphous silicon layer is interposed between the contact grid and the blanket layer.
Then, the blanket layer outside the trenches is removed and MRAM elements are formed in the trenches.