410070: GYM103937 E Diverse Debaters
Description
ACM 4 Change is hosting a series of ethical debates, and they have brought a panel of $$$N$$$ speakers who are experts on a variety of ethical topics to open the floor. Each speaker is distinguished by a unique ID $$$i$$$ ($$$1 \leq i \leq N$$$) and specializes in a particular area denoted by an integer $$$a_i$$$. After lining up all the speakers in a row in increasing order of ID, the officers for ACM need to select some number of speakers to kickstart debates during the meeting. They want exactly $$$K$$$ distinct areas of expertise to be represented by the minimum possible number of speakers, but require all the picked speakers to be part of a contiguous sequence in the row (e.g. if speakers with IDs $$$a$$$ and $$$b$$$ are picked with $$$a \leq b$$$, any speaker with ID $$$x$$$ with $$$a \leq x \leq b$$$ must also be selected). What is the minimum number of panel members that must be chosen to speak?
InputThe first line of input contains two space separated-integers $$$N$$$ and $$$K$$$ ($$$1 \leq N, K \leq 10^5$$$), representing the number of panel speakers and the exact number of distinct topics A4C would like debaters to go over, respectively. The second line of input contains $$$N$$$ space-separated integers $$$a_i$$$ ($$$1 \leq a_i \leq 10^5$$$) that represent the topic of expertise of the $$$i$$$-th speaker. Two speakers with IDs $$$i$$$ and $$$j$$$ have the same area of expertise if and only if $$$a_i = a_j$$$.
OutputOutput the minimum number of panel speakers necessary to meet the requirements of having exactly $$$K$$$ distinct topics covered. If this is not possible with the given speakers, output $$$-1$$$ instead.
ExamplesInput4 2 1 2 2 3Output
2Input
5 1337 1 22 333 4444 55555Output
-1Note
In the first sample case, the first two speakers or the last two speakers can be selected.
In the second sample case, there are not enough distinct topics covered by the panel speakers.