#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf=0x3f,INF=0x3f3f3f3f; const ll LLINF=0x3f3f3f3f3f3f3f3f;
#define sz(x) (int)x.size()
#define af(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x);
#define fil(x, y) fill(af(x), y);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second	
#define lc i << 1
#define rc i << 1 | 1
const int mod = 1e9 + 7;
ll fpow(ll a, ll b){ll ret=1;while(b){if(b&1)ret=ret*a%mod;a=a*a%mod,b>>=1;}return ret;}
ll inv(ll x){return x ? fpow(x, mod - 2) : 1;}
void madd(int &a, int b){a+=b;if(a>=mod)a-=mod;}
void msub(int &a, int b){a+=mod-b;if(a>=mod)a-=mod;}
const int MM = 2e5 + 5;

void solve(){
	int n, k;
	cin >> n >> k;
	vector<vector<int>> g(n, vector<int>(n));
	for (auto &v : g) for (auto &x : v) cin >> x;
	vector<int> ord(n);
	for (int i = 0; i < n; i++) ord[i] = i;
	int ans = 0;
	do{
		int sum = 0;
		for (int i = 0; i < n; i++)
			sum += g[ord[i]][ord[(i+1)%n]];
		ans += sum == k && ord[0] == 0;
	} while(next_permutation(af(ord)));
	cout << ans << '\n';
}
int main(){
	cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) solve();
}

#include<iostream>
#include<cstdio>
#include<cstring>
#define MAXM 25
typedef long long ll;
using namespace std;

ll n,m;
ll cnt[3],ans;
char a[MAXM];

int main(){
	cin>>n>>m;
	ll zz = 0;
	for(int i = 1 ; i <= n ; i++){
		zz = 0;
		scanf("%s" , a + 1);
		for(int j = 1 ; j <= m ; j++)zz += (a[j] == '1');
		zz %= 2;
		if(zz % 2 == 1)ans += cnt[0];
		else ans += cnt[1];
		cnt[zz]++;
	}
	cout<<ans<<endl;
}