题目链接:http://codeforces.com/problemset/problem/818/D
#include<bits/stdc++.h>
using namespace std;#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define read(x,y) scanf("%d%d",&x,&y)
#define ll long long#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
const int maxn =1e6+5;
const int mod=1e9+7;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
///数据域
int n,m,x;
int cnt[maxn],ret=0;int main()
{scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){scanf("%d",&x);if(x==m) ret++;else if(cnt[x]>=ret) cnt[x]++;///不选他作为答案}int ans=-1;for(int i=1;i<maxn;i++){if(i==m) continue;if(cnt[i]>=ret) {ans=i;break;}}printf("%d\n",ans);return 0;
}