#Q123. 「一本通 4.2 例 3」与众不同
「一本通 4.2 例 3」与众不同
Description
A is the CEO of a company. Every month, employees send the company's profit data to A. A is an eccentric person who doesn't focus on whether the company is making a profit or a loss, but rather enjoys studying "perfect sequences": a continuous sequence where all numbers are distinct.
A wants to know the length of the longest perfect sequence within the interval .
Input Format
The first line contains two integers and , where represents consecutive months, numbered from to , and represents the number of queries.
The second line contains integers, where the -th number represents the profit value of the company in the -th month.
The next lines each contain two integers and , representing the interval queried by A.
Output Format
Output lines, each containing an integer representing the length of the longest perfect sequence within the queried interval.
Sample 1
9 2
2 5 4 1 2 3 6 2 4
0 8
2 6
6
5
Constraints and Hints
For all data, , , and .