CF818D Multicolored Cars

题目描述

Alice 和 Bob 在长途汽车旅行中十分无聊,于是玩了一个游戏。 Alice 先选择一种颜色 $A$,然后 Bob 选择一个与 $A$ 不同的颜色 $B$。令 $cnt_x(y)$ 表示截至时间 $y$,颜色为 $x$ 的汽车在窗外出现过的次数。 Bob 已经知道了 Alice 选择的颜色 $A$。为了获胜,他要选择一个合法的 $B$,满足在在任意时刻 $i$ $(1 \le i \le n)$,$cnt_A(i) \le cnt_B(i)$。 Bob 请你帮助他找到一个满足要求的颜色 $B$,如果没有请输出 $-1$。

输入格式

第一行两个整数 $n, A$ $(1 \le n \le 10^5, 1 \le A \le 10^6)$,表示有 $n$ 个数,Alice 选择了颜色 $A$。 第二行 $n$ 个整数 $a_{1},a_{2},\cdots,a_{n}$ $(1 \le a_i \le 10^6)$,$a_{i}$ 表示时刻 $i$ 出现的车的颜色。

输出格式

如果存在这样的 $B$ $(1 \le B \le 10^6)$ 请输出任意一个可行解,若不存在合法的 $B$ 请输出 $-1$。

说明/提示

Let's consider availability of colors in the first example: - $ cnt_{2}(i)>=cnt_{1}(i) $ for every $ i $ , and color $ 2 $ can be the answer. - $ cnt_{4}(2)<cnt_{1}(2) $ , so color $ 4 $ isn't the winning one for Bob. - All the other colors also have $ cnt_{j}(2)<cnt_{1}(2) $ , thus they are not available. In the third example every color is acceptable except for $ 10 $ .