Construction of M matrix