import sys, time, random from collections import deque, Counter, defaultdict input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 n, mod = mi() A = [li() for _ in range(n)] ppcnt = [0] * (1 << n) for i in range(1, 1<> i): cnt -= 1 if not(1 & (bit >> i)): if cnt % 2: dpsum[bit | (1 << i)][1] += dpsum[bit][0] * A[ppcnt[bit]][i] dpsum[bit | (1 << i)][0] += dpsum[bit][1] * A[ppcnt[bit]][i] dpsum[bit | (1 << i)][0] %= mod dpsum[bit | (1 << i)][1] %= mod else: dpsum[bit | (1 << i)][1] += dpsum[bit][1] * A[ppcnt[bit]][i] dpsum[bit | (1 << i)][0] += dpsum[bit][0] * A[ppcnt[bit]][i] dpsum[bit | (1 << i)][0] %= mod dpsum[bit | (1 << i)][1] %= mod print(dpsum[-1][1])