#include <bits/stdc++.h>
using namespace std;
int n, m, a[200005], b[200005], cnt, AC, mx = 0, x;
int main() {
  scanf("%d%d", &n, &m);
  cnt = 0;
  for (int i = (1); i <= (n); i++) {
    scanf("%d", &x);
    if (x != a[cnt]) a[++cnt] = x;
  }
  memset(b, 0, sizeof(b));
  for (int i = (1); i <= (cnt); i++)
    if (a[i - 1] == a[i + 1])
      b[a[i]] += 2;
    else
      b[a[i]] += 1;
  for (int i = (1); i <= (m); i++)
    if (b[i] > mx) AC = i, mx = b[i];
  printf("%d\n", AC);
  return 0;
}
