#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define qi queue<int>
#define sti stack<int>
#define fi first
#define se second
#define pb push_back
const int N=200+5;
int n;
int b[N],len[N];
ll a[N][N],p;
int lowbit(int x){
return x&(-x);
}
void add(int x){
for (int i=x;i<=n;i+=lowbit(i))len[i]++;
}
int getsum(int x){
int t=0;
for (int i=x;i>0;i-=lowbit(i))t+=len[i];
return t;
}
int main(){
freopen ("det.in","r",stdin);
freopen ("det.out","w",stdout);
scanf("%d%lld",&n,&p);
for (int i=1;i<=n;i++){
for (int j=1;j<=n;j++){
scanf("%lld",&a[i][j]);
}
}
for (int i=1;i<=n;i++)b[i]=i;
ll ans=0;
do{
for (int i=1;i<=n;i++)len[i]=0;
int cnt=0;ll w=1;
for (int i=n;i>=1;i--){
cnt+=getsum(b[i]);
add(b[i]);
w=w*a[i][b[i]]%p;
}
if (cnt&1)w*=-1;
ans=((ans+w)%p+p)%p;
}while(next_permutation(b+1,b+n+1));
printf("%lld\n",ans);
return 0;
}