#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 998244353;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, k;
int gr[55][55];

int fact[MAXN];
int p1[MAXN], p2[MAXN];
int sz1[MAXN], sz2[MAXN];
int find_set(int *p, int a){
    if(p[a] == a) return a;
    return p[a] = find_set(p, p[a]);
}

void merge(int a, int b, int *p){
    a = find_set(p, a);
    b = find_set(p, b);
    if(a != b){
        p[b] = a;
        if(p == p1)
            sz1[a] += sz1[b];
        else 
            sz2[a] += sz2[b];
    }
}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif

    fact[0] = 1;

    for(int i = 1; i <= 50; i++)
        fact[i] = 1LL * fact[i - 1] * i % mod;

    cin>>n>>k;

    for(int i = 0; i < n; i++){
        p1[i] = i;
        sz1[i] = 1;
        p2[i] = i;
        sz2[i] = 1;
        for(int j = 0; j < n; j++)
            cin>>gr[i][j];
    }
    int ans = 1;

    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            bool tru = 1;
            for(int l = 0; l < n; l++){
                if(gr[i][l] + gr[j][l] > k){
                    tru = 0;
                    break;
                }
            }
            if(tru)
                merge(i, j, p1);
        }
    }

    for(int i = 0; i < n; i++){
        if(p1[i] == i){
            ans = 1LL * ans * fact[sz1[i]] % mod;
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            bool tru = 1;
            for(int l = 0; l < n; l++){
                if(gr[l][i] + gr[l][j] > k){
                    tru = 0;
                    break;
                }
            }
            if(tru)
                merge(i, j, p2);
        }
    }

    for(int i = 0; i < n; i++){
        if(p2[i] == i){
            ans = 1LL * ans * fact[sz2[i]] % mod;
        }
    }

    cout<<ans<<endl;

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
//#define int long long
int n,m,a[1500010],f[1500010];
signed main() {
	memset(f,0,sizeof(f));
	scanf("%d%d",&n,&m);
	for(int i = 1; i <= n; i++) {
		scanf("%d",&a[i]);
	}
	for(int i = 1; i <= m; i++) {
		f[a[i]]++;
	}
	int ans;
	for(int i = 0; ; i++) {
		if(f[i] == 0) {
			ans = i;
			break;
		}
	}
	for(int i = 2; i+m-1 <= n; i++) {
		if(a[i-1] < ans && a[i+m-1] != a[i-1] && f[a[i-1]] == 1) {
			ans = a[i-1];
		}
		f[a[i-1]]--;
		f[a[i+m-1]]++;
	}
	cout << ans << endl;
	return 0;
}