luogu#P5093. [USACO04OPEN] The Cow Lineup

[USACO04OPEN] The Cow Lineup

Problem Description

John’s NN cows (1N1000001 \leq N \leq 100000) are standing in a line. Each cow has a tag number that shows her breed, and the tag number is in the range 1K1 \ldots K (1K100001 \leq K \leq 10000).

For example, there is a lineup like this: 1,5,3,2,5,3,4,4,2,5,1,2,3.

With his sharp math sense, John finds that some subsequences appear in this lineup, such as "3,4,1,3", while others do not. Other numbers may appear between the elements of the subsequence; if so, the subsequence is still considered to exist. Now he wants to use integers from 1K1 \sim K to construct the shortest subsequence that does not appear in the cow sequence. What is the length of such a subsequence?

Input Format

The first line contains two integers NN and KK. The next NN lines contain the cow sequence.

Output Format

Output one line: the length of the shortest subsequence that does not appear.

14 5
1
5
3
2
5
1
3
4
4
2
5
1
2
3
3

Hint

Explanation of the sample:

All possible subsequences of length 11 and 22 appear, but the subsequence of length 33, "2,2,4", does not appear.

Translated by ChatGPT 5