#include <bits/stdc++.h>
using namespace std;

const int maxn=200010;

int n,m;
string s;
char t[maxn];

int main()
{
	cin>>n>>s;
	for(int i=0;i<n;i++)
	{
		t[++m]=s[i];

		if(m>=3&&t[m-2]=='f'&&t[m-1]=='o'&&t[m]=='x') m-=3;
	}

	cout<<m;
	
	return 0;
}
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (200006)
ll n, K, mod=998244353, grid[52][52], sz[52], f[52];
struct u_ {
	int p[52];
	u_() { FOR(i,0,51) p[i]=i; }
	void merge(int x,int y) { p[find(x)]=find(y); }
	ll find(ll x){return p[x]==x?x:p[x]=find(p[x]);}
} ufds;
ll ans=1;
void funny() {
	mmst(sz,0);
	FOR(i,0,n-1) ++ sz[ufds.find(i)];
	FOR(i,0,n-1) if(ufds.find(i) == i) {
		ans *= f[sz[i]], ans %= mod;
	}
}
int main(){
	FAST
	cin>>n>>K;
	f[0]=1; FOR(i,1,51) f[i]=f[i-1]*i%mod;
	FOR(i,0,n-1) FOR(j,0,n-1) {
		cin>>grid[i][j];
	}
	ufds = u_();
	FOR(i,0,n-1) {
		FOR(k,0,n-1) if(i^k) {
			bool can = 1;
			FOR(j,0,n-1) {
				if(grid[i][j] + grid[k][j] > K) can = 0;
			}
			if(can) ufds.merge(i, k);
		}
	}
	funny();
	ufds = u_();
	FOR(j,0,n-1) {
		FOR(k,0,n-1) if(j^k) {
			bool can = 1;
			FOR(i,0,n-1) {
				if(grid[i][j] + grid[i][k] > K) can = 0;
			}
			if(can) ufds.merge(j, k);
		}
	}
	funny();
	cout<<ans<<'\n';
}
