You are given a sequence and independent queries. For each query, you are provided with two natural numbers and . Consider the subsequence . Your task is to calculate the sum of the minimum excluded numbers of all subsequences of the form , for .
The minimum excluded number of a subsequence is the smallest natural number that does not appear in the subsequence. For example, for the subsequence , it is , but for the subsequence , it is .
Input data
The first line of the input contains the numbers and . The second line contains numbers , which represent the initial sequence. Each of the following lines contains two numbers and , which describe, respectively, each query.
Output data
The output should contain the answers to the queries in order, each on a new line.
Constraints
Subtask 1 (3 points)
Subtask 2 (10 points)
- for each query
Subtask 3 (12 points)
Subtask 4 (15 points)
- Each number from to appears exactly once in .
Subtask 5 (15 points)
- There are no two queries and such that and .
Subtask 6 (22 points)
- for each query.
Subtask 7 (23 points)
- No additional constraints.
Example
stdin
6 3
0 1 2 0 1 3
1 2
3 5
1 6
stdout
3
7
39
Explanations
Explanations for the first two queries:
Explanation for the third query: