#abc194e. [abc194_e]Mex Min
[abc194_e]Mex Min
Problem Statement
Let us define as the smallest non-negative integer that does not occur in .
You are given an integer sequence of length : .
For each integer such that , we compute $\\mathrm{mex}(A_{i + 1}, A_{i + 2}, A_{i + 3}, \\dots, A_{i + M})$. Find the minimum among the results of these computations.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 2
0 0 1
Sample Output 1
1
We have:
- for : $\\mathrm{mex}(A_{i + 1}, A_{i + 2}) = \\mathrm{mex}(0, 0) = 1$
- for : $\\mathrm{mex}(A_{i + 1}, A_{i + 2}) = \\mathrm{mex}(0, 1) = 2$
Thus, the answer is the minimum among and , which is .
Sample Input 2
3 2
1 1 1
Sample Output 2
0
We have:
- for : $\\mathrm{mex}(A_{i + 1}, A_{i + 2}) = \\mathrm{mex}(1, 1) = 0$
- for : $\\mathrm{mex}(A_{i + 1}, A_{i + 2}) = \\mathrm{mex}(1, 1) = 0$
Sample Input 3
3 2
0 1 0
Sample Output 3
2
We have:
- for : $\\mathrm{mex}(A_{i + 1}, A_{i + 2}) = \\mathrm{mex}(0, 1) = 2$
- for : $\\mathrm{mex}(A_{i + 1}, A_{i + 2}) = \\mathrm{mex}(1, 0) = 2$
Sample Input 4
7 3
0 0 1 2 0 1 0
Sample Output 4
2