#include <bits/stdc++.h>
using namespace std;
vector<long long> v[100007];
long long ar[100009], cr[100004];
int main() {
  long long n, m;
  cin >> n >> m;
  long long k;
  long long in = 1;
  ar[0] = 0;
  for (long long i = 1; i <= n; i++) {
    cin >> k;
    if (ar[in - 1] != k) {
      v[k].push_back(in);
      ar[in++] = k;
      cr[k]++;
    }
  }
  long long mx = 0;
  long long ck = 0;
  long long ans = ar[1];
  for (long long i = 1; i <= m; i++) {
    long long cnt = 0;
    for (long long j = 0; j < v[i].size(); j++) {
      long long ind = v[i][j];
      if (ind != 1 && ind != in - 1) {
        if (ar[ind - 1] == ar[ind + 1]) cnt++;
      }
    }
    cnt += cr[i];
    if (mx < cnt) {
      mx = cnt;
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}
