def main(): import sys input = sys.stdin.read().split() idx = 0 N = int(input[idx]) idx += 1 B = int(input[idx]) idx += 1 A = [] for _ in range(N): row = list(map(int, input[idx:idx+N])) idx += N A.append(row) mod = 2 * B max_mask = 1 << N dp = [0] * max_mask dp[0] = 1 bit_count = [0] * max_mask for mask in range(max_mask): bit_count[mask] = bin(mask).count('1') for k in range(N): for mask in range(max_mask): if bit_count[mask] != k: continue current = dp[mask] if current == 0: continue for j in range(N): if not (mask & (1 << j)): new_mask = mask | (1 << j) val = (current * A[k][j]) % mod dp[new_mask] = (dp[new_mask] + val) % mod P = dp[(1 << N) - 1] def compute_determinant(mat): n = len(mat) det = 1 mat = [row[:] for row in mat] for c in range(n): pivot_row = -1 for r in range(c, n): if mat[r][c] != 0: pivot_row = r break if pivot_row == -1: return 0 if pivot_row != c: mat[c], mat[pivot_row] = mat[pivot_row], mat[c] det *= -1 for r in range(c + 1, n): while mat[r][c] != 0: factor = mat[r][c] // mat[c][c] for j in range(c, n): mat[r][j] -= factor * mat[c][j] if mat[r][c] != 0: mat[c], mat[r] = mat[r], mat[c] det *= -1 det *= mat[c][c] return det D = compute_determinant(A) D_mod = D % mod diff = (P - D_mod) % mod O = (diff // 2) % B print(O) if __name__ == "__main__": main()