Baby Ehab has a piece of Cut and Stick with an array a of length n written on it. He plans to grab a pair of scissors and do the following to it:

  * pick a range (l, r) and cut out every element a_l, a_{l + 1}, ..., a_r in this range; 
  * stick some of the elements together in the same order they were in the array; 
  * end up with multiple pieces, where every piece contains some of the elements and every element belongs to some piece. 



More formally, he partitions the sequence a_l, a_{l + 1}, ..., a_r into subsequences. He thinks a partitioning is beautiful if for every piece (subsequence) it holds that, if it has length x, then no value occurs strictly more than ⌈ x/2 ⌉ times in it.

He didn't pick a range yet, so he's wondering: for q ranges (l, r), what is the minimum number of pieces he needs to partition the elements a_l, a_{l + 1}, ..., a_r into so that the partitioning is beautiful.

A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Note that it does not have to be contiguous.

Input

The first line contains two integers n and q (1 ≤ n,q ≤ 3 ⋅ 10^5) — the length of the array a and the number of queries.

The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_i ≤ n) — the elements of the array a.

Each of the next q lines contains two integers l and r (1 ≤ l ≤ r ≤ n) — the range of this query.

Output

For each query, print the minimum number of subsequences you need to partition this range into so that the partitioning is beautiful. We can prove such partitioning always exists.

Example

Input


6 2
1 3 2 3 3 2
1 6
2 5


Output


1
2

Note

In the first query, you can just put the whole array in one subsequence, since its length is 6, and no value occurs more than 3 times in it.

In the second query, the elements of the query range are [3,2,3,3]. You can't put them all in one subsequence, since its length is 4, and 3 occurs more than 2 times. However, you can partition it into two subsequences: [3] and [2,3,3].
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 300005
using namespace std;

int n,m,blo,a[N],b[N];
int t[N],ans[N],cnt[N],res;
struct que{int l,r,id,bel;}q[N];

inline int qr()
{
	char a=0;int w=1,x=0;
	while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();}
	while(a<='9'&&a>='0'){x=(x<<3)+(x<<1)+(a^48);a=getchar();}
	return x*w;
}

inline bool cmp1(que a,que b)
{
	return a.bel^b.bel ? a.bel<b.bel : (a.bel&1) ? (a.r<b.r) : (a.r>b.r);
}

inline void Ins(int pos)
{
	--t[cnt[a[pos]]];
	++t[++cnt[a[pos]]];
	res=max(res,cnt[a[pos]]);
}

inline void Del(int pos)
{
	--t[cnt[a[pos]]];
	if(!t[cnt[a[pos]]]&&res==cnt[a[pos]]) res--;
	++t[--cnt[a[pos]]];
}
int Left[N],Right[N];
int main()
{
	n=qr(),m=qr();blo=max((int)(n/pow(m,0.5)),1);
	for(register int i=1;i<=n;i++) b[i]=a[i]=qr();
	sort(b+1,b+n+1);
	for(register int i=1;i<=n;i++) a[i]=lower_bound(b+1,b+n+1,a[i])-b;
	for(register int i=1;i<=m;i++) q[i]=(que){Left[i]=qr(),Right[i]=qr(),i},q[i].bel=(q[i].l-1)/blo+1;
	sort(q+1,q+m+1,cmp1);
	int L=1,R=0;
	for(register int i=1;i<=m;i++)
	{
		while(L>q[i].l) Ins(--L);
		while(L<q[i].l) Del(L++);
		while(R<q[i].r) Ins(++R);
		while(R>q[i].r) Del(R--);
		ans[q[i].id]=res;
	}
	for(register int i=1;i<=m;i++){
		if(ans[i]<=(Right[i]-Left[i]+2)/2){
			printf("%d\n",1);
		}else{
			int len=Right[i]-Left[i]+1;
			printf("%d\n",len-((len-ans[i])*2+1)+1);
		}
	}
	return 0;
}
/*
区间内部取子序列,使得子序列没有值出现超过len/2(向上取整)次,问最少分成多少个子序列 (区间符合要求就不需要分,答案为1)
考虑到n为3e5,可能每次的判断是O(1)的(或许经过一些预处理) 
找到一个区间众数,如果这个众数的数量不超过len/2(上取整),那直接合法 
然后剩下的数的数量一定不超过这个数的数量,设剩下的数有x个,则x个剩下的数和x+1个众数可以合一个自序列,然后剩下的众数单独成序列 

*/