#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll maxn=200005;

const ll mod=998244353;
const ll INF64 = ll(1e18);
const ll max2=10500000;

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
vector<ll> adj_row[52],adj_column[52];
ll vis_r[52],vis_c[52];
ll dfs(ll p,vector<ll> adj[],ll vis[])
{
	vis[p]=1;
	ll i;
	ll x=1;
	for(i=0;i<adj[p].size();++i)
	{
		if(vis[adj[p][i]]==0)
		{
			x+=dfs(adj[p][i],adj,vis);
		}
	}
	return(x);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
//long long tt = clock();
#endif
ios_base::sync_with_stdio(NULL);  cin.tie(0); cout.tie(0);
ll n,c,i,j,k;
cin>>n>>c;
ll a[n][n];
for(i=0;i<n;++i)
{
	for(j=0;j<n;++j)
		cin>>a[i][j];
}
ll fact[52];
fact[0]=1;
for(i=1;i<=n;++i)
{
	fact[i]=(fact[i-1]*i)%mod;
}

for(i=0;i<n;++i)
{	
	for(j=i+1;j<n;++j)
	{ll sum=0;
		for(k=0;k<n;++k)
			sum+=(a[i][k]+a[j][k]<=c);

		if(sum==n)
		{	
			adj_column[i].push_back(j);
			adj_column[j].push_back(i);
		}
	}

}
for(i=0;i<n;++i)
{	
	for(j=i+1;j<n;++j)
	{ll sum=0;
		for(k=0;k<n;++k)
			sum+=(a[k][i]+a[k][j]<=c);
		if(sum==n)
		{//cout<<i<<" "<<j<<"\n";
			adj_row[i].push_back(j);
			adj_row[j].push_back(i);
		}
	}

}
//return(0);
ll ans=1;
for(i=0;i<n;++i)
{
	if(vis_c[i]==0)
	{
		ll x=dfs(i,adj_column,vis_c);
		
		ans=(ans*fact[x])%mod;
	}
	if(vis_r[i]==0)
		{ll x=dfs(i,adj_row,vis_r);
			//cout<<x<<" "<<i<<"\n";
		//return(0);
			ans=(ans*fact[x])%mod;
		}
}
cout<<ans;

return(0);
}
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define Pii pair<int,int>
#define Pll pair<long long,long long>
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

using namespace std;

constexpr ll MOD = 1e9+7;

long long powmod(long long x,long long n){
    long long ret=1;
    while(n>0){
        if(n&1){
            ret*=x;
            ret%=MOD;
            n-=1;
        }else{
            x*=x;
            x%=MOD;
            n>>=1;
        }
    }
    return ret;
}

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    ll m; cin >> m;
    vector<ll> a(n);
    ll sum = 0;
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }
    ll ans = 1;
    for(ll i=1;i<=n+sum;i++){
        ans *= (n+m+1-i)%MOD;
        ans %= MOD;
        ans *= powmod(i,MOD-2);
        ans %= MOD;
    }
    cout << ans  << endl;
    
    return 0;
}
// g++ main.cpp -o a.out && ./a.out