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].
import java.io.*;import java.util.*;import java.math.*;
public class Main
{
	public void tq()throws Exception
	{
		st=new StringTokenizer(br.readLine());
		int tq=1;
		sb=new StringBuilder(1000000);
		o:
		while(tq-->0)
		{
			int n=i();
			int q=i();
			int ar[]=ari(n);
			int qq[][]=new int[q][3];
			int bl=(int)(Math.sqrt(n));
			for(int x=0;x<q;x++)
			{
				int a=i();
				int b=i();
				qq[x][0]=a-1;
				qq[x][1]=b-1;
				qq[x][2]=x;
			}
			Arrays.sort(qq,(aa,bb)->
			{
				if(aa[0]/bl!=bb[0]/bl)return (aa[0]-bb[0]<=0?-1:1);
                return (aa[1]-bb[1]<=0?-1:1);
			});
			int f[]=new int[n+1];
			int ff[]=new int[n+1];
			ff[0]=n;
			int l=0;
			int r=-1;
			int m=0;
			int fi[]=new int[q];
			for(int e[]:qq)
			{
//				p(e);
				while(l>e[0])
				{
		            l--;
		            ff[f[ar[l]]]--;
		            f[ar[l]]++;
		            ff[f[ar[l]]]++;
		            if(f[ar[l]]==m+1)m++;
		        }
//				p(f);
//		        p(ff);
		        while(r<e[1])
		        {
		            r++;
		            ff[f[ar[r]]]--;
		            f[ar[r]]++;
		            ff[f[ar[r]]]++;
		            if(f[ar[r]]==m+1)m++;
		        }
//		        p(f);
//		        p(ff);
		        while(l<e[0])
		        {
		        	if(f[ar[l]]==m&&ff[f[ar[l]]]==1)m--;
		        	ff[f[ar[l]]]--;
		        	f[ar[l]]--;
		        	ff[f[ar[l]]]++;
		            l++;
		        }
//		        p(f);
//		        p(ff);
		        while(r>e[1])
		        {
		        	if(f[ar[r]]==m&&ff[f[ar[r]]]==1)m--;
		        	ff[f[ar[r]]]--;
		        	f[ar[r]]--;
		        	ff[f[ar[r]]]++;
		            r--;
		        }
//		        p(f);
//		        p(ff);
		        int d=e[1]-e[0]+1;
		        d=(d+3)/2;
		        if(m>=d)
		        {
		        	int nn=(e[1]-e[0]+1);
		    		int le=nn-m;
		    		fi[e[2]]=nn-2*le;
		        }
		        else fi[e[2]]=1;
			}
			for(int x:fi)sl(x);
		}
		p(sb);
	}
    
    long mod=1000000007l;int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;
    long maxl=Long.MAX_VALUE,minl=Long.MIN_VALUE;
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;StringBuilder sb;
    public static void main(String[] a)throws Exception{new Main().tq();}
    int[] so(int ar[]){Integer r[]=new Integer[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];
    Arrays.sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
    long[] so(long ar[]){Long r[]=new Long[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];
    Arrays.sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
    char[] so(char ar[])
    {Character r[]=new Character[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];
    Arrays.sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
    void s(String s){sb.append(s);}void s(int s){sb.append(s);}void s(long s){sb.append(s);}
    void s(char s){sb.append(s);}void s(double s){sb.append(s);}
    void ss(){sb.append(' ');}void sl(String s){sb.append(s);sb.append("\n");}
    void sl(int s){sb.append(s);sb.append("\n");}
    void sl(long s){sb.append(s);sb.append("\n");}void sl(char s){sb.append(s);sb.append("\n");}
    void sl(double s){sb.append(s);sb.append("\n");}void sl(){sb.append("\n");}
    int min(int a,int b){return a<b?a:b;}
    int min(int a,int b,int c){return a<b?a<c?a:c:b<c?b:c;}
    int max(int a,int b){return a>b?a:b;}
    int max(int a,int b,int c){return a>b?a>c?a:c:b>c?b:c;}
    long min(long a,long b){return a<b?a:b;}
    long min(long a,long b,long c){return a<b?a<c?a:c:b<c?b:c;}
    long max(long a,long b){return a>b?a:b;}
    long max(long a,long b,long c){return a>b?a>c?a:c:b>c?b:c;}
    int abs(int a){return Math.abs(a);}
    long abs(long a){return Math.abs(a);}
    int sq(int a){return (int)Math.sqrt(a);}long sq(long a){return (long)Math.sqrt(a);}
    long gcd(long a,long b){while(b>0l){long c=a%b;a=b;b=c;}return a;}
    int gcd(int a,int b){while(b>0){int c=a%b;a=b;b=c;}return a;}
    boolean pa(String s,int i,int j){while(i<j)if(s.charAt(i++)!=s.charAt(j--))return false;return true;}
    boolean[] si(int n)
    {boolean bo[]=new boolean[n+1];bo[0]=true;bo[1]=true;for(int x=4;x<=n;x+=2)bo[x]=true;
    for(int x=3;x*x<=n;x+=2){if(!bo[x]){int vv=(x<<1);for(int y=x*x;y<=n;y+=vv)bo[y]=true;}}
    return bo;}long mul(long a,long b,long m) 
    {long r=1l;a%=m;while(b>0){if((b&1)==1)r=(r*a)%m;b>>=1;a=(a*a)%m;}return r;}
    int i()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
    return Integer.parseInt(st.nextToken());}
    long l()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
    return Long.parseLong(st.nextToken());}String s()throws IOException
    {if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());return st.nextToken();}
    double d()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
    return Double.parseDouble(st.nextToken());}void p(Object p){System.out.print(p);}
    void p(String p){System.out.print(p);}void p(int p){System.out.print(p);}
    void p(double p){System.out.print(p);}void p(long p){System.out.print(p);}
    void p(char p){System.out.print(p);}void p(boolean p){System.out.print(p);}
    void pl(Object p){System.out.println(p);}void pl(String p){System.out.println(p);}
    void pl(int p){System.out.println(p);}void pl(char p){System.out.println(p);}
    void pl(double p){System.out.println(p);}void pl(long p){System.out.println(p);}
    void pl(boolean p){System.out.println(p);}void pl(){System.out.println();}
    void s(int a[]){for(int e:a){sb.append(e);sb.append(' ');}sb.append("\n");}
    void s(long a[]){for(long e:a){sb.append(e);sb.append(' ');}sb.append("\n");}
    void s(int ar[][]){for(int a[]:ar){for(int e:a){sb.append(e);sb.append(' ');}sb.append("\n");}}
    void s(char a[]){for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}
    void s(char ar[][]){for(char a[]:ar){for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}}
    int[] ari(int n)throws IOException
    {int ar[]=new int[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
    for(int x=0;x<n;x++)ar[x]=Integer.parseInt(st.nextToken());return ar;}
    int[][] ari(int n,int m)throws IOException
    {int ar[][]=new int[n][m];for(int x=0;x<n;x++){if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
    for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken());}return ar;}
    long[] arl(int n)throws IOException
    {long ar[]=new long[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
    for(int x=0;x<n;x++) ar[x]=Long.parseLong(st.nextToken());return ar;}
    long[][] arl(int n,int m)throws IOException
    {long ar[][]=new long[n][m];for(int x=0;x<n;x++)
    {if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
    for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken());}return ar;}
    String[] ars(int n)throws IOException
    {String ar[]=new String[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
    for(int x=0;x<n;x++) ar[x]=st.nextToken();return ar;}
    double[] ard(int n)throws IOException
    {double ar[]=new double[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
    for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken());return ar;}
    double[][] ard(int n,int m)throws IOException
    {double ar[][]=new double[n][m];for(int x=0;x<n;x++)
    {if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
    for(int y=0;y<m;y++)ar[x][y]=Double.parseDouble(st.nextToken());}return ar;}
    char[] arc(int n)throws IOException{char ar[]=new char[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
    for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0);return ar;}
    char[][] arc(int n,int m)throws IOException{char ar[][]=new char[n][m];
    for(int x=0;x<n;x++){String s=br.readLine();for(int y=0;y<m;y++)ar[x][y]=s.charAt(y);}return ar;}
    void p(int ar[]){StringBuilder sb=new StringBuilder(11*ar.length);
    for(int a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
    void p(int ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
    for(int a[]:ar){for(int aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
    void p(long ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
    for(long a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
    void p(long ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
    for(long a[]:ar){for(long aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
    void p(String ar[]){int c=0;for(String s:ar)c+=s.length()+1;StringBuilder sb=new StringBuilder(c);
    for(String a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
    void p(double ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
    for(double a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
    void p(double ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
    for(double a[]:ar){for(double aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
    void p(char ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
    for(char aa:ar){sb.append(aa);sb.append(' ');}System.out.println(sb);}
    void p(char ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
    for(char a[]:ar){for(char aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
}