#include <bits/stdc++.h>
using namespace std;
const int MAXA = 1000000;
int D[1 + MAXA], K[1 + MAXA + 1], P[1 + MAXA];
int main()
{
int k, n;
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
int a;
cin >> a;
D[a] = max(D[a], i - P[a]);
P[a] = i;
}
for (int i = 1; i <= MAXA; ++i) {
D[i] = max(D[i], n + 1 - P[i]);
K[D[i]] = i;
}
cout << K[k] << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTUFYQSA9IDEwMDAwMDA7CgppbnQgRFsxICsgTUFYQV0sIEtbMSArIE1BWEEgKyAxXSwgUFsxICsgTUFYQV07CgppbnQgbWFpbigpCnsKICAgIGludCBrLCBuOwogICAgY2luID4+IG4gPj4gazsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47ICsraSkgewogICAgICAgIGludCBhOwogICAgICAgIGNpbiA+PiBhOwogICAgICAgIERbYV0gPSBtYXgoRFthXSwgaSAtIFBbYV0pOwogICAgICAgIFBbYV0gPSBpOwogICAgfQogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gTUFYQTsgKytpKSB7CiAgICAgICAgRFtpXSA9IG1heChEW2ldLCBuICsgMSAtIFBbaV0pOwogICAgICAgIEtbRFtpXV0gPSBpOwogICAgfQogICAgY291dCA8PCBLW2tdIDw8IGVuZGw7CiAgICByZXR1cm4gMDsKfQ==