You are given a sequence a_1,…,a_n and q independent queries. In each query you are given two integers l and r. Consider the sequence a_l,a_l+1,…,a_r. Your task is to compute the sum of the minimum excluded element of all sequences of form a_i,a_i+1,…,a_j, for l≤i≤j≤r.
The minimum excluded element of a sequence is the smallest non-negative integer that does not appear in the sequence. For example, for the sequence 0, 1, 4, 2 it is 3, but the for the sequence 1, 2, 3, 4 it is 0.
The first line of the input contains the integers n and q. The second line contains n integers a_1,a_2,…,a_n, representing the initial sequence. Each of the next q lines contains two integers l and r, describing each query.
The output should contain the answers to the q queries in order, each on a new line.
Explanation for the first queries:
| Subsequence | Min. excl. elem. |
|---|---|
| 0 | 1 |
| 1 | 0 |
| 0, 1 | 2 |
| Total: | 3 |
Explanation for the second queries:
| Subsequence | Min. excl. elem. |
|---|---|
| 2 | 0 |
| 0 | 1 |
| 1 | 0 |
| 2, 0 | 1 |
| 0, 1 | 2 |
| 2, 0, 1 | 3 |
| Total: | 7 |
Explanation for the third query:
| Subsequence | Min. excl. elem. |
|---|---|
| 0 | 1 |
| 0, 1 | 2 |
| 0, 1, 2 | 3 |
| 0, 1, 2, 0 | 3 |
| 0, 1, 2, 0, 1 | 3 |
| 0, 1, 2, 0, 1, 3 | 4 |
| 1 | 0 |
| 1, 2 | 0 |
| 1, 2, 0 | 3 |
| 1, 2, 0, 1 | 3 |
| 1, 2, 0, 1, 3 | 4 |
| 2 | 0 |
| 2, 0 | 1 |
| 2, 0, 1 | 3 |
| 2, 0, 1, 3 | 4 |
| 0 | 1 |
| 0, 1 | 2 |
| 0, 1, 3 | 2 |
| 1 | 0 |
| 1, 3 | 0 |
| 3 | 0 |
| Total: | 39 |