def solve(): N, B = map(int, input().split()) A = [None] * N for i in range(N): A[i] = list(map(int, input().split())) A[i] = [a % B for a in A[i]] popcount = [0] * (1 << N) for S in range(1, 1 << N): x = S & (-S) popcount[S] = popcount[S ^ x] + 1 bit = lambda S,k : (S>>k) & 1 DP0 = [0] * (1 << N); DP0[0] = 1 DP1 = [0] * (1 << N) for S in range(1 << N): t = 0 i = popcount[S] for k in range(N): if not bit(S, k): T = S | (1 << k) if t % 2 == 0: DP0[T] += DP0[S] * A[i][k]; DP0[T] %= B DP1[T] += DP1[S] * A[i][k]; DP1[T] %= B else: DP0[T] += DP1[S] * A[i][k]; DP0[T] %= B DP1[T] += DP0[S] * A[i][k]; DP1[T] %= B t += 1 return DP1[-1] #================================================== print(solve())