#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 [L,R][L, R].

Input Format

The first line contains two integers NN and MM, where NN represents NN consecutive months, numbered from 00 to N1N-1, and MM represents the number of queries.

The second line contains NN integers, where the ii-th number represents the profit value aia_i of the company in the ii-th month.

The next MM lines each contain two integers LL and RR, representing the interval queried by A.

Output Format

Output MM 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, 1N,M2×1051\le N,M\le 2\times 10^5, 0LRN10\le L\le R\le N-1, and ai106|a_i|\le 10^6.