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

using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;

#define sz(x) (int)(x).size()

template <typename T> bool ckmin (T& a, T b) { return (b < a) ? a = b, 1 : 0; }
template <typename T> bool ckmax (T& a, T b) { return (b > a) ? a = b, 1 : 0; }

#ifdef XVENOM
  #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: " << dbg_str(__VA_ARGS__)
#else
  #define dbg(...) ;
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const char* e) { return "\"" + string(e) + "\""; }
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
  string s = "[ "; for (auto& x : e) s += to_string(x) + " "; return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
  return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
string dbg_str () { return " \n"; }
template <typename U, typename... V> string dbg_str (U u, V... v) {
  return " " + to_string(u) + dbg_str(v...);
}
/* *** */
const int N = 55;
const ll Mod = 998244353;
int n, k, a[N][N];
int s[N], p[N];
ll fac[N];

ll mul (ll u, ll v) { return ((u % Mod) * (v % Mod)) % Mod; }
ll add (ll u, ll v) { return (u + v) % Mod; }

void init() {
  for (int i = 0; i < n; i++) {
    s[i] = 1;
    p[i] = i;
  }
}

int leader (int x) { return p[x] == x ? x : (p[x] = leader(p[x])); }
void combine (int u, int v) {
  u = leader(u); v = leader(v);
  if (u == v) return;
  if (s[u] > s[v]) swap(u, v);
  p[u] = v;
  s[v] += s[u];
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);

  fac[0] = 1;
  for (int i = 1; i < N; i++) fac[i] = mul(fac[i - 1], i);

  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }


  auto can_swap_cols = [&] (int u, int v) {
    for (int i = 0; i < n; i++) {
      if (a[i][u] + a[i][v] > k) return false;
    }
    return true;
  };

  auto can_swap_rows = [&] (int u, int v) {
    for (int i = 0; i < n; i++) {
      if (a[u][i] + a[v][i] > k) return false;
    }
    return true;
  };
  
  ll ans = 1;
  init();
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (can_swap_rows(i, j)) combine(i, j);
    }
  }
  
  for (int i = 0; i < n; i++) if (leader(i) == i) {
    ans = mul(ans, fac[s[i]]);
  }

  init();
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (can_swap_cols(i, j)) combine(i, j);
    }
  }

  for (int i = 0; i < n; i++) if (leader(i) == i) {
    ans = mul(ans, fac[s[i]]);
  }

  cout << ans << '\n';
}

#include <bits/stdc++.h>
using namespace std;
#define boostIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, b, a) for (int i = b; i >= a; i--)
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define sz(v) (int)(v.size())
#define all(v) v.begin(), v.end()
#define mem(a, val) memset(a, val, sizeof(a))
#define trav(a, x) for (auto &a : x)
#define ppcll(x) __builtin_popcountll(x)
void amn(int &x, int y) { x = min(x, y); }
void amx(int &x, int y) { x = max(x, y); }

#define mod 1000000007
const long long INF = 1e18;
// const int N = 5e5 + 5;

signed main() {
	boostIO;
	int n, m;
	cin >> n >> m;
	int a[n], b[m];
	set<int> sa, sb;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sa.insert(a[i]);
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
		sb.insert(b[i]);
	}
	set<int> ans;
	for (int i = 0; i < n; i++) {
		if (sb.count(a[i]) == 0) {
			ans.insert(a[i]);
		}
	}
	for (int i = 0; i < m; i++) {
		if (sa.count(b[i]) == 0) {
			ans.insert(b[i]);
		}
	}
	for (int i : ans) {
		cout << i << " ";
	} cout << endl;
	return 0;
}
// Play Hard Kiddo...