// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
#define int long long
#define all(a) a.begin(), a.end()
#define vi vector<int>
#define pii pair<int, int>
#define fe(i, a, b) for (int i = a; i <= (b); ++i)
#define fr(i, a, b) for (int i = b; i >= (a); --i)
using namespace std;

inline int in() {
    int s = 0, f = 0, ch = getchar();
    while (!isdigit(ch))
        f |= ch == '-', ch = getchar();
    while (isdigit(ch))
        s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
    return f ? -s : s;
}
const int N = 1e6 + 5;
const int mod = 998244353;
const int inf = ~(1ULL << 63);
int n, m, k;
int a[N], b[N], f[N];
int c[N];

int qp(int a, int b) {
    int sum = 1;
    while (b) {
        if (b & 1)
            sum = sum * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return sum;
}
int inv(int a) {
    return qp(a, mod - 2);
}
bool flag[N];
int p[N], tot;

int find(int x) {
    return x == f[x] ? x : f[x] = find(f[x]);
}

struct node {
    int x, y;
};

int toint(string s, int r) {
    int ans = 0;
    for (auto i : s) {
        ans = ans * r + i - 48;
    }
    return ans;
}

node ve[N + 1];
void work() {
    n = in(), m = in();
    fe(i, 1, n) { a[i] = in(); }
    int tot = 0;
    fe(i, 1, m) { f[a[i]]++; }
    for (; f[tot]; tot++)
        ;

    int ans = tot;
    fe(i, 1, n - m) {
        f[a[i]]--;
        f[a[i + m]]++;
        if (f[a[i]] == 0 && tot > a[i]) {
            tot = a[i];
        }
        ans = min(ans, tot);
    }
    cout << ans;
}
signed main() {
#ifndef ONLINE_JUDGE
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
#endif
    // for (int _ = in(); _; --_)
    work();
    // system("pause");
    return 0;
}
#include <cstdio>
#include <vector>

typedef long long LL;
const int Mod = 998244353;
const int MN = 55;

int N, K, A[MN][MN], Ans;
std::vector<int> G[MN];

int c, vis[MN];
void DFS(int u) {
	vis[u] = 1;
	Ans = (LL)Ans * ++c % Mod;
	for (int v : G[u]) if (!vis[v]) DFS(v);
}

int main() {
	scanf("%d%d", &N, &K), Ans = 1;
	for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= N; ++j)
			scanf("%d", &A[i][j]);
	for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= N; ++j) if (i < j) {
			int ok = 1;
			for (int k = 1; k <= N; ++k)
				if (A[i][k] + A[j][k] > K)
					ok = 0;
			if (ok)
				G[i].push_back(j),
				G[j].push_back(i);
		}
	for (int i = 1; i <= N; ++i) if (!vis[i]) c = 0, DFS(i);
	for (int i = 1; i <= N; ++i) G[i].clear(), vis[i] = 0;
	for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= N; ++j) if (i < j) {
			int ok = 1;
			for (int k = 1; k <= N; ++k)
				if (A[k][i] + A[k][j] > K)
					ok = 0;
			if (ok)
				G[i].push_back(j),
				G[j].push_back(i);
		}
	for (int i = 1; i <= N; ++i) if (!vis[i]) c = 0, DFS(i);
	printf("%d\n", Ans);
	return 0;
}