import numpy as np n, b = map(int, input().split()) a = np.array([[*map(int, input().split())] for _ in [0] * 3]) d = np.linalg.det(a) ans = int(d) % b print(ans)