/
Time Limit: 2 sec / Memory Limit: 1024 MiB
問題文
M 種類の賞品 1,2,\dots,M が当たるくじ引きがあります。
これを N 回引いたところ、 i 回目は賞品 A_i を引きました。
以下の条件を満たす最小の整数 k を求めてください。ただし、そのような k が存在しない場合は代わりに -1 と答えてください。
- k 回目のくじ引きが終わった時点で、 M 種類全ての賞品を少なくとも 1 回は引いている。
制約
- 入力は全て整数
- 1 \le N,M \le 100
- 1 \le A_i \le M
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_N
出力
答えを整数として出力せよ。
入力例 1
10 4 3 1 4 1 4 3 2 1 3 4
出力例 1
7
賞品は M=4 種あり、各回のくじ引きで賞品 3,1,4,1,4,3,2,1,3,4 を引きました。
7 回目のくじ引きが終わった時点で 4 種類全ての賞品を少なくとも 1 回は引いています。
また、 k=7 が問題文中の条件を満たす最小です。
入力例 2
8 5 1 2 3 4 4 3 2 1
出力例 2
-1
問題文中の条件を満たす整数 k は存在しません。
入力例 3
20 6 1 2 3 1 4 3 4 3 2 3 5 3 1 1 3 3 3 1 6 4
出力例 3
19
Problem Statement
There is a lottery with M kinds of prizes: 1,2,\dots,M.
There were N draws, the i-th of which awarded prize A_i.
Find the minimum integer k satisfying the following condition. If there is no such k, report -1 instead.
- After the k-th draw, each of the M kinds of prizes has been awarded at least once.
Constraints
- All input values are integers.
- 1 \le N,M \le 100
- 1 \le A_i \le M
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \dots A_N
Output
Print the answer as an integer.
Sample Input 1
10 4 3 1 4 1 4 3 2 1 3 4
Sample Output 1
7
There are M=4 kinds of prizes, and the draws awarded prizes 3,1,4,1,4,3,2,1,3,4.
After the 7-th draw, each of the 4 kinds of prizes has been awarded at least once.
Also, k=7 is the smallest integer satisfying the condition in the problem statement.
Sample Input 2
8 5 1 2 3 4 4 3 2 1
Sample Output 2
-1
No integer k satisfies the condition in the problem statement.
Sample Input 3
20 6 1 2 3 1 4 3 4 3 2 3 5 3 1 1 3 3 3 1 6 4
Sample Output 3
19