

実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
長さ N の整数列 A=(A_1,A_2,\dots,A_N) および正整数 M が与えられます。
A の末尾の要素を削除するという操作を 0 回以上 N 回以下行うことで、以下の条件が満たされないようにしたいです。
- 条件:A には 1 以上 M 以下の整数がすべて含まれている。
必要な操作回数の最小値を求めてください。
なお、本問題の制約下において、操作を 0 回以上 N 回以下行うことで上述の条件が満たされないようにすることが必ず可能であることが証明できます。
制約
- 1\leq M \leq N \leq 100
- 1\leq A_i \leq M
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_N
出力
条件が満たされなくなるために必要な操作回数の最小値を出力せよ。
入力例 1
5 3 3 2 3 1 2
出力例 1
2
最初、A=(3,2,3,1,2) です。このとき、A には 1 以上 3 以下の整数がすべて含まれるため条件を満たします。
A の末尾の要素を削除する操作を 1 回行うと、A=(3,2,3,1) となります。このとき、A には 1 以上 3 以下の整数がすべて含まれるため条件を満たします。
A の末尾の要素を削除する操作をもう 1 回行うと、A=(3,2,3) となります。このとき、A には 1 が含まれないため条件を満たしません。
よって、条件が満たされなくなるために必要な操作回数の最小値は 2 です。
入力例 2
4 3 1 3 1 3
出力例 2
0
A には最初から 2 が含まれず条件を満たさないため、操作を 1 回も行う必要がありません。
入力例 3
10 4 1 3 3 4 2 1 3 1 2 4
出力例 3
6
Score : 200 points
Problem Statement
You are given an integer sequence A = (A_1, A_2, \dots, A_N) of length N and a positive integer M.
Your goal is to make the following condition false by performing this operation between 0 and N times (inclusive): remove the last element of A.
- Condition: A contains every integer from 1 through M.
Find the minimum number of operations required.
Under the constraints of this problem, it can be proved that it is always possible to make the condition false by performing the operation between 0 and N times.
Constraints
- 1 \le M \le N \le 100
- 1 \le A_i \le M
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \dots A_N
Output
Output the minimum number of operations required to make the condition false.
Sample Input 1
5 3 3 2 3 1 2
Sample Output 1
2
Initially, A = (3,2,3,1,2). Since A contains every integer from 1 through 3, the condition holds.
If you perform the operation once, A = (3,2,3,1). The condition still holds.
If you perform the operation once more, A = (3,2,3). The integer 1 is missing, so the condition no longer holds.
Therefore, the minimum required number of operations is 2.
Sample Input 2
4 3 1 3 1 3
Sample Output 2
0
Since A initially lacks the integer 2, the condition is already false, so no operation is needed.
Sample Input 3
10 4 1 3 3 4 2 1 3 1 2 4
Sample Output 3
6