creating matrix M