atcoder#ABC290C. [ABC290C] Max MEX

[ABC290C] Max MEX

Score : 300300 points

Problem Statement

You are given a length-NN sequence of non-negative integers. When BB is a sequence obtained by choosing KK elements from AA and concatenating them without changing the order, find the maximum possible value of MEX(B)MEX(B).

Here, for a sequence XX, we define MEX(X)MEX(X) as the unique non-negative integer mm that satisfies the following conditions:

  • Every integer ii such that 0i<m0 \le i < m is contained in XX.
  • mm is not contained in XX.

Constraints

  • All values in the input are integers.
  • 1KN3×1051 \le K \le N \le 3 \times 10^5
  • 0Ai1090 \le A_i \le 10^9

Input

The input is given from Standard Input in the following format:

NN KK

A1A_1 A2A_2 \dots ANA_N

Output

Print the answer.

7 3
2 0 2 3 2 1 9
3

In this input, A=(2,0,2,3,2,1,9)A=(2,0,2,3,2,1,9), and you obtain the sequence BB by picking K=3K=3 elements. For example,

  • If the 11-st, 22-nd, and 33-rd elements are chosen, MEX(B)=MEX(2,0,2)=1MEX(B)=MEX(2,0,2)=1.
  • If the 33-rd, 44-th, and 66-th elements are chosen, MEX(B)=MEX(2,3,1)=0MEX(B)=MEX(2,3,1)=0.
  • If the 22-nd, 66-th, and 77-th elements are chosen, MEX(B)=MEX(0,1,9)=2MEX(B)=MEX(0,1,9)=2.
  • If the 22-nd, 33-rd, and 66-th elements are chosen, MEX(B)=MEX(0,2,1)=3MEX(B)=MEX(0,2,1)=3.

The maximum possible MEXMEX is 33.