After reading an article on the Longest Increasing Subsequence problem, your friend Lucas is interested in other problems involving increasing subsequences.
Recently, he has started asking you about increasing subsequences with large 'gaps'. Given a sequence , an increasing subsequence with non-negative gap
is a sequence of indices
such that for all
we have that
.
Note that Lucas does not need the sequence to be strictly increasing. Specifically, he is fine if and
.
In particular, given a sequence of integers
he wants you to find the largest (non-negative) integer
such that there exists an increasing subsequence of
with gap
. As this is too easy if you can choose small subsequences, he wants the subsequence to have length at least
.
Unfortunately, when he wrote down his sequence some of the numbers got corrupted and were changed to
. He now wants you to find the largest non-negative value
such that you can find a sequence
that matches
in all uncorrupted locations and has an increasing subsequence with gap
. Lucas wants you to consider
that contain negative (and zero) integers, even though he is sure that his original uncorrupted
contained only positive integers.
If no valid exist, instead output
-1
and if the set of valid is unbounded, output
Infinity
.
Constraints
or
Subtask 1 [20%]
Subtask 2 [30%]
Subtask 3 [50%]
No additional constraints.
Input Specification
The first line contains two integers: and
.
The second line contains integers:
for
.
Output Specification
Output the maximum possible subsequence gap, or -1
if no such subsequence exists.
If the maximum possible gap is unbounded, output Infinity
.
Sample Input 1
10 10
4 -1 -1 23 -1 54 -1 -1 63 -1
Sample Output 1
3
Sample Input 2
10 5
4 -1 74 23 643 54 33 5 63 -1
Sample Output 2
35
Sample Input 3
10 6
-1 5 -1 4 -1 3 -1 2 -1 1
Sample Output 3
Infinity
Sample Input 4
10 6
1 5 2 4 3 3 4 2 5 1
Sample Output 4
0
Sample Input 5
10 7
1 5 2 4 3 3 4 2 5 1
Sample Output 5
-1
Comments