N,mod=map(int,input().split()) dp=[[0]*(2**(N+1)) for i in range(N)] z=2**N z*=N u=[0]*z for bit in range(2**N): v=[] for k in range(N): if (bit>>k)&1: v.append(k) count=0 for x in range(N): for j in range(len(v)-1,-1,-1): if v[j]>x: count+=1 else: break count%=2 u[N*bit+x]=count A=[list(map(int,input().split())) for i in range(N)] for i in range(N): for j in range(N): A[i][j]%=mod for j in range(N): bit=2**j if j<100: dp[0][2*bit]=A[0][j] else: dp[0][2*bit+1]=A[0][j] for i in range(N-1): for bit in range(2**N): for k in range(2): if dp[i][2*bit+k]==0: continue for j in range(N): if (bit>>j)&1: continue w=u[N*bit+j] if w==0: k2=k dp[i+1][2*(bit+2**j)+k2]+=dp[i][2*bit+k]*A[i+1][j] dp[i+1][2*(bit+2**j)+k2]%=mod else: k2=(k+1)%2 dp[i+1][2*(bit+2**j)+k2]+=dp[i][2*bit+k]*A[i+1][j] dp[i+1][2*(bit+2**j)+k2]%=mod result=dp[N-1][2**(N+1)-1] result%=mod print(result)