#include <bits/stdc++.h>

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 55, MOD = 998244353;
int dsu[N], sz[N];

int find(int u){
	return dsu[u]==u ? u : dsu[u] = find(dsu[u]);
}

void unite(int u, int v){
	u = find(u), v = find(v);
	if(u==v) return;
	if(sz[u] > sz[v]) swap(u,v);
	dsu[u] = v;
	sz[v] += sz[u];
}

signed main(){
	fastio
	int n,k;
	cin >> n >> k;
	iota(dsu,dsu+N,0);
	fill(sz,sz+N,1);
	int arr[n][n];
	for(int i = 0;i < n;i++) for(int j = 0;j < n;j++) cin >> arr[i][j];
	int ans = 1;
	for(int i = 0;i < n;i++){
		for(int j = i+1;j < n;j++){
			bool ok = true;
			for(int l = 0;l < n;l++){
				if(arr[i][l]+arr[j][l] > k) ok = false;
			}
			if(ok){
				unite(i,j);
			}
		}
	}
	for(int i = 0;i < n;i++) if(dsu[i] == i) for(int j = 1;j <= sz[i];j++) ans = ans*j%MOD;
	iota(dsu,dsu+N,0);
	fill(sz,sz+N,1);
	for(int i = 0;i < n;i++){
		for(int j = i+1;j < n;j++){
			bool ok = true;
			for(int l = 0;l < n;l++){
				if(arr[l][i]+arr[l][j] > k) ok = false;
			}
			if(ok) unite(i,j);
		}
	}
	for(int i = 0;i < n;i++) if(dsu[i] == i) for(int j = 1;j <= sz[i];j++) ans = ans*j%MOD;
	cout << ans << "\n";
}
#include <bits/stdc++.h>

using namespace std;

#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
using tp = tuple<ll, ll, ll>;

constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;

using Array = vector<ll>;
using Matrix = vector<Array>;

/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Edge {
    ll to, cap, rev;

    Edge(ll _to, ll _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll) G[to].size()));
    if (revFlag)
        G[to].push_back(Edge(from, revCap, (ll) G[from].size() - 1));
}

map<ll, ll> mp;

ll rec(ll x) {
    if (mp.find(x) != mp.end()) return mp[x];
    ll ret = INF;
    if ((ll) 2e9 + 10 >= x) chmin(ret, x * 1);
    chmin(ret, rec(x / 2) + 1 + x % 2 * 1);
    if ((x + 1) / 2 != x) chmin(ret, rec((x + 1) / 2) + 1 + x % 2 * 1);
    return mp[x] = ret;
}

void solve() {
    ll x, y;
    cin >> x >> y;
    if (x >= y) {
        cout << x - y << en;
    }else{
        priority_queue<P, vec<P>, greater<P>> que;
        que.push({0, y});
        ll ans = INF;
        map<ll, ll> mp;
        mp[y]++;
        while (que.size()) {
            auto[num,val] = que.top();
            que.pop();
            if (num > ans) continue;
            if(val<=x){
                chmin(ans, num+x-val);
            }else{
                chmin(ans,num+val-x);
            }
            if (val % 2 == 1) {
                if (!mp.count(val + 1) and ans > num + 1) {
                    mp[val + 1]++;
                    que.push({num + 1, val + 1});
                }
                if (!mp.count(val - 1) and ans > num + 1) {
                    mp[val - 1]++;
                    que.push({num + 1, val - 1});
                }
            }else{
                if(mp.count(val/2) or ans <= num+1) continue;
                que.push({num+1,val/2});
            }
        }
        cout<<ans<<en;
    }

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    REP(i, t - 1) {
        solve();
    }*/

    solve();

    return 0;
}
