#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector <int> a(n);
    vector <vector <int>> pos(n);

    rep (i, n) {
        cin >> a[i];
        pos[a[i]].push_back(i);
    }

    int ans = 0;
    rep (i, n) {
        if (pos[i].size() == 0) break;
        rep (j, pos[i].size()) {
            int tmp = j == 0 ? pos[i][j] - (-1)
                             : pos[i][j] - pos[i][j - 1];

            if (tmp > m) {
                cout << i << endl;
                return 0;
            }
        }
        if (n - pos[i].back() > m) break;
        ans += 1;
    }
    cout << ans << endl;

    return 0;
}
#include<bits/stdc++.h>
#define rep(a,b,c) for(register int a=(b);a<=(c);++a)
#define dow(a,b,c) for(register int a=(b);a>=(c);--a)
using namespace std;
const int MaxN=1000000+5;
struct Connector
{
	int fa[MaxN];
	inline void Initalize(const register int len)
	{
		rep(i,1,len)
			fa[i]=i;
	}
	inline int getf(const register int u)
	{
		if(u!=fa[u])
			fa[u]=getf(fa[u]);
		return fa[u];
	}
	inline bool Merge(const register int u,const register int v)
	{
		const register int fu=getf(u),fv=getf(v);
		if(fu==fv)
			return false;
		fa[fu]=fv;
		return true;
	}
};
Connector con;
int arr[MaxN];
int main()
{
	register int n,m=0;
	scanf("%d",&n);
	rep(i,1,n)
		scanf("%d",&arr[i]),m=max(m,arr[i]);
	con.Initalize(m);
	register int Sum=0;
	rep(i,1,n>>1)
		if(con.Merge(arr[i],arr[n-i+1]))
			++Sum;
	printf("%d\n",Sum);
	return 0;
}