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<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int ksiz,ans,c[N],s[N],anss[N];
struct node{int l,r,id;}a[N];
void read(int &x){
	int f=1;x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
bool cmp(node q,node p){
	int t1=(q.l-1)/ksiz,t2=(p.l-1)/ksiz;
	return t1^t2?t1<t2:q.r<p.r;
}
void add(int x){
	if(!c[s[x]])ans++;
	c[s[x]]++;
}
void del(int x){
	c[s[x]]--;
	if(!c[s[x]])ans--;
}
int main(){
	int n,m,i,x,y;
	read(n),read(m),ksiz=sqrt(n);
	for(i=1;i<=n;i++)read(s[i]);
	for(i=1;i<=m;i++)
		read(x),read(y),a[i]=(node){x,y,i};
	sort(a+1,a+1+m,cmp);
	int l=1,r=0;
	for(i=1;i<=m;i++){
		int ql=a[i].l,qr=a[i].r;
		while(l<ql)del(l++);
		while(l>ql)add(--l);
		while(r<qr)add(++r);
		while(r>qr)del(r--);
		anss[a[i].id]=ans;
	}
	for(i=1;i<=m;i++)
		printf("%d\n",anss[i]);
	return 0;
}
