Minho's Wish

No attempts yetTime limit2sMemory limit512 MB

Problem

Minho has a sequence A1,A2,,ANA_1, A_2, \dots, A_N of length NN. He names two integers xx and yy, then asks how many different numbers appear at least three times in the range [x,y][x, y].

Report the number of distinct values, not the total number of occurrences. For example, if the numbers in the range are 1,3,3,3,3,2,2,2,7,1,71, 3, 3, 3, 3, 2, 2, 2, 7, 1, 7, then 33 appears four times and 22 appears three times, so the answer is 22.

Answer all QQ of Minho's wishes.

Input

The first line contains NN and QQ separated by a space (1N,Q1000001 \le N, Q \le 100\,000), the length of Minho's sequence and the number of wishes he will name.

The second line contains the elements AiA_i in order, separated by spaces (1Ai1000001 \le A_i \le 100\,000, 1iN1 \le i \le N).

Each of the next QQ lines contains xx and yy for one wish, separated by a space (1xyN1 \le x \le y \le N).

Output

Print the answer to each wish on its own line, in the order the wishes are given.