A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to k.

On the i-th day the festival will show a movie of genre a_{i}. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a_1, a_2, ..., a_{n} at least once.

Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site.

As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress.

Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies.

Valentine wants to choose such genre x (1 ≤ x ≤ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum.


-----Input-----

The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 10^5), where n is the number of movies and k is the number of genres.

The second line of the input contains a sequence of n positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ k), where a_{i} is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence.


-----Output-----

Print a single number — the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number.


-----Examples-----
Input
10 3
1 1 2 3 2 3 3 1 1 3

Output
3
Input
7 3
3 1 3 2 3 1 2

Output
1


-----Note-----

In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses.

In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.

Difficulty: MEDIUM_HARD
Tags: Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
(n, k) = map(int, input().split())
r = list(map(int, input().split()))
dist = []
ans = [0] * (k + 1)
for i in range(n):
	if i == 0 or r[i] != r[i - 1]:
		dist.append(r[i])
for i in range(len(dist)):
	if 0 < i < len(dist) - 1 and dist[i - 1] == dist[i + 1]:
		ans[dist[i]] += 2
	else:
		ans[dist[i]] += 1
(u, v) = (-1, -1)
for k in range(1, k + 1):
	if ans[k] > u:
		(u, v) = (ans[k], k)
print(v)


import math
from collections import Counter
import math
import bisect
(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
ls = [0] * (10 ** 5 + 1)
pre = arr[0]
for i in range(1, n - 1):
	if arr[i] != arr[i + 1]:
		ls[arr[i]] += 2 if arr[i + 1] == pre else 1
		pre = arr[i]
if arr[0] != arr[-1]:
	ls[arr[-1]] += 1
	if arr[0] != arr[1]:
		ls[arr[0]] += 1
var = ls.index(max(ls))
mm = max(ls)
if m == 2:
	if 1 in arr and 2 in arr:
		print(1)
	else:
		print(0)
else:
	for i in range(len(ls)):
		if ls[i] == mm:
			print(i)
			break


(num_days, num_genres) = list(map(int, input().split()))
schedule = list(map(int, input().split()))
compressed = []
current = schedule[0]
pos = 1
while True:
	compressed.append(current)
	while pos < num_days and schedule[pos] == current:
		pos += 1
	if pos < num_days:
		current = schedule[pos]
	else:
		break
score = (num_genres + 1) * [0]
score[compressed[0]] += 1
for i in range(2, len(compressed)):
	score[compressed[i - 1]] += 1
	if compressed[i - 2] == compressed[i]:
		score[compressed[i - 1]] += 1
score[compressed[len(compressed) - 1]] += 1
(best_score, best_genre) = (-1, -1)
for genre in range(1, num_genres + 1):
	if score[genre] > best_score:
		best_score = score[genre]
		best_genre = genre
print(best_genre)


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return list(map(int, minp().split()))
(n, k) = mints()
a = list(mints())
i = 0
c = [0] * (k + 1)
while i < n:
	j = i
	while j < n and a[j] == a[i]:
		j += 1
	if i - 1 >= 0:
		if j < n:
			if a[i - 1] != a[j]:
				c[a[i]] += 1
			else:
				c[a[i]] += 2
		else:
			c[a[i]] += 1
	elif j < n:
		c[a[i]] += 1
	i = j
z = 1
for i in range(k + 1):
	if c[z] < c[i]:
		z = i
print(z)


(n, k) = list(map(int, input().split()))
lis = list(map(int, input().split()))
ans = []
freq = [0] * (k + 1)
for i in range(n - 1):
	if lis[i] != lis[i + 1]:
		ans.append(lis[i])
if lis[-1] != ans[-1]:
	ans.append(lis[-1])
l = len(ans)
for i in range(1, l - 1):
	if ans[i - 1] == ans[i + 1]:
		freq[ans[i]] += 2
	else:
		freq[ans[i]] += 1
freq[ans[-1]] += 1
freq[ans[0]] += 1
print(freq.index(max(freq)))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [a[0]]
	for i in range(1, n):
		if a[i] == b[-1]:
			continue
		else:
			b += [a[i]]
	di = {}
	for i in range(len(b)):
		if b[i] not in di:
			di[b[i]] = []
		di[b[i]] += [i]
	total = len(b) - 1
	ans = [0] * (k + 1)
	for i in range(1, k + 1):
		ans[i] = total - len(di[i])
	for i in range(1, k + 1):
		for j in range(len(di[i])):
			if di[i][j] and di[i][j] + 1 != len(b) and (b[di[i][j] - 1] == b[di[i][j] + 1]):
				ans[i] -= 1
	ans[0] = 9999999999999
	print(ans.index(min(ans)))


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
s = [0 for i in range(k)]
b = [a[0]]
for i in range(1, n):
	if a[i] == b[-1]:
		continue
	else:
		b.append(a[i])
y = len(b)
for i in range(y):
	if i == 0 and b[i] != b[i + 1]:
		s[a[0] - 1] += 1
	elif i == y - 1 and b[i] != b[i - 1]:
		s[b[y - 1] - 1] += 1
	elif b[i - 1] == b[i + 1]:
		s[b[i] - 1] += 2
	else:
		s[b[i] - 1] += 1
x = max(s)
print(s.index(x) + 1)


import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None
		self.BUFSIZE = 8192

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split(' ')))

def get_int_grid(n):
	return [get_ints() for _ in range(n)]

def get_str():
	return input().split(' ')

def yes_no(b):
	if b:
		return 'YES'
	else:
		return 'NO'

def binary_search(good, left, right, delta=1, right_true=False):
	limits = [left, right]
	while limits[1] - limits[0] > delta:
		if delta == 1:
			mid = sum(limits) // 2
		else:
			mid = sum(limits) / 2
		if good(mid):
			limits[int(right_true)] = mid
		else:
			limits[int(~right_true)] = mid
	if good(limits[int(right_true)]):
		return limits[int(right_true)]
	else:
		return False

def prefix_sums(a):
	p = [0]
	for x in a:
		p.append(p[-1] + x)
	return p

def solve_a():
	n = get_int()
	a = get_ints()
	negs = 0
	cnt = 0
	ans = []
	for i in range(n):
		cnt += 1
		if a[i] < 0:
			negs += 1
		if negs == 3:
			ans.append(cnt - 1)
			cnt = 1
			negs = 1
	ans.append(cnt)
	return ans

def solve_b():
	s = input()
	pass

def solve_c():
	(n, k) = get_ints()
	a = get_ints()
	a_uniq = []
	for x in a:
		if len(a_uniq) == 0 or x != a_uniq[-1]:
			a_uniq.append(x)
	m = len(a_uniq)
	d = defaultdict(int)
	for i in range(m):
		if 0 < i < m - 1 and a_uniq[i + 1] == a_uniq[i - 1]:
			d[a_uniq[i]] += 2
		else:
			d[a_uniq[i]] += 1
	m = -1
	j = -1
	for i in range(1, k + 1):
		if i in d and d[i] > m:
			(m, j) = (d[i], i)
	return j
print(solve_c())


import sys

def solve():
	(n, k) = map(int, input().split())
	bada = list(map(int, input().split()))
	a = list()
	for i in range(len(bada)):
		if len(a) > 0 and bada[i] == a[-1]:
			continue
		a.append(bada[i])
	bad = [0] * (k + 1)
	for (i, val) in enumerate(a):
		if i + 1 >= len(a) and i == 0:
			continue
		if i + 1 >= len(a):
			bad[val] += 1
		elif i == 0:
			bad[val] += 1
		else:
			before = a[i - 1]
			after = a[i + 1]
			bad[val] += 2 if before == after else 1
	which = -1
	howmany = -1
	for i in range(len(bad)):
		if bad[i] > howmany:
			which = i
			howmany = bad[i]
	print(which)
if sys.hexversion == 50594544:
	sys.stdin = open('test.txt')
solve()


(n, k) = list(map(int, input().split()))
t = list(map(int, input().split()))
t = [t[0]] + [t[i] for i in range(1, len(t)) if t[i] != t[i - 1]]
p = [0] * (k + 1)
for i in range(1, len(t) - 1):
	if t[i - 1] == t[i + 1]:
		p[t[i]] += 2
	else:
		p[t[i]] += 1
p[t[0]] += 1
p[t[-1]] += 1
print(p.index(max(p)))


(n, k) = map(int, input().split())
lst = [*map(int, input().split())]
(a, length) = ([lst[0]], 0)
for (i, x) in enumerate(lst[1:]):
	if x != lst[i]:
		a.append(x)
		length += 1
d = {i: length for i in range(1, k + 1)}
d[a[0]] -= 1
for (i, x) in enumerate(a[1:-1]):
	if a[i] == a[i + 2]:
		d[x] -= 2
	else:
		d[x] -= 1
d[a[-1]] -= 1
res = min(d.values())
for (i, x) in enumerate(d):
	if d[x] == res:
		print(x)
		break


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
a = [0] + a + [0]
i = 1
tot = 0
j = 1
cnt = [0] * (k + 1)
while i <= n:
	while j <= n and a[j] == a[i]:
		j += 1
	tot += 1
	if a[i - 1] == a[j]:
		cnt[a[i]] += 2
	else:
		cnt[a[i]] += 1
	i = j
tot -= 1
ans = tot
for i in range(1, k + 1):
	if ans > tot - cnt[i]:
		ans = tot - cnt[i]
		res = i
print(res)


__author__ = 'Michael Ilyin'

def prepare(a):
	na = []
	last = 0
	for i in range(0, len(a)):
		if last != a[i]:
			na.append(a[i])
			last = a[i]
	return na
header = input()
films = int(header[:header.find(' ')])
genres = int(header[header.find(' '):])
numbers = [int(x) for x in input().split()]
res = [[genre, 0] for genre in range(1, genres + 1)]
numbers = prepare(numbers)
films = len(numbers)
for (i, obj) in enumerate(numbers):
	if i == 0:
		res[obj - 1][1] += 1
		continue
	if i == films - 1:
		res[obj - 1][1] += 1
		continue
	if numbers[i - 1] == numbers[i + 1]:
		res[obj - 1][1] += 2
	else:
		res[obj - 1][1] += 1
res = sorted(res, key=lambda x: x[0], reverse=False)
res = sorted(res, key=lambda x: x[1], reverse=True)
print(str(res[0][0]))


(n, k) = [int(x) for x in input().strip().split(' ')]
dataF = input().strip().split(' ')
dataF = [int(x) for x in dataF]
data = [0]
for i in range(len(dataF)):
	if data[len(data) - 1] != dataF[i]:
		data.append(dataF[i])
data = data[1:]
res = {x: 0 for x in set(data)}
res[data[0]] += 1
res[data[len(data) - 1]] += 1
for i in range(0, len(data) - 2, 1):
	prev = data[i]
	curr = data[i + 1]
	next = data[i + 2]
	if prev == next:
		res[curr] += 2
	if prev != next:
		res[curr] += 1
print(max(res, key=res.get))