We have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.

You are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?

Constraints

* 1\leq N,Q \leq 5 \times 10^5
* 1\leq c_i \leq N
* 1\leq l_i \leq r_i \leq N
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N Q
c_1 c_2 \cdots c_N
l_1 r_1
l_2 r_2
:
l_Q r_Q


Output

Print Q lines. The i-th line should contain the response to the i-th query.

Examples

Input

4 3
1 2 1 3
1 3
2 4
3 3


Output

2
3
1


Input

10 10
2 5 6 5 2 1 7 9 7 2
5 5
2 4
6 7
2 2
7 8
7 9
1 8
6 9
8 10
6 8


Output

1
2
2
1
2
2
6
3
3
3
#include <stdio.h>
#include <algorithm>
struct str{
	int x0;
	int y0;
	int index;
	int ans;
}y[500010];
bool cmp(str a, str b)
{
	if(a.x0/700==b.x0/700) return a.y0<b.y0;
	return (a.x0/700)<(b.x0/700);
}
bool cmp2(str a, str b)
{
	return a.index<b.index;
}

int C = 0;
int count[500010];
void func(int k)
{
	if(count[k]==0) C++;
	count[k]++;
}
void func2(int k)
{
	if(count[k]==1) C--;
	count[k]--;
}

int x[500010];
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=a;i++) scanf("%d",&x[i]);
	for(int i=1;i<=b;i++)
	{
		int c,d;
		scanf("%d%d",&c,&d);
		y[i]={c,d,i,0};
	}
	std::sort(y+1,y+b+1,cmp);
	
	for(int i=y[1].x0;i<=y[1].y0;i++) func(x[i]);
	y[1].ans = C;
	
	int L = y[1].x0, R = y[1].y0;
	for(int i=2;i<=b;i++)
	{
		if(y[i].y0>=R) while(R<y[i].y0) func(x[++R]);
		else while(R>y[i].y0) func2(x[R--]);
		
		if(y[i].x0<=L) while(L>y[i].x0) func(x[--L]);
		else while(L<y[i].x0) func2(x[L++]);
		
		y[i].ans = C;
	}
	std::sort(y+1,y+b+1,cmp2);
	for(int i=1;i<=b;i++) printf("%d\n",y[i].ans);
}