human
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].
Using python3 can you solve the prior task?
 What is a Python code to print the minimum number of subsequences you need to partition this range into so that the partitioning is beautiful?
assistant
#Here is Python code to print the minimum number of subsequences you need to partition this range into so that the partitioning is beautiful.

# from random import randint
from bisect import bisect_left as bl

def main():
    
    n,q=readIntArr()
    a=readIntArr()
    
    idxes=[[] for _ in range(n+1)]
    for i,x in enumerate(a):
        idxes[x].append(i)
    
    def getCnts(l,r,elem):
        le=bl(idxes[elem],l)
        ri=bl(idxes[elem],r)
        cnts=ri-le
        if ri<len(idxes[elem]) and idxes[elem][ri]==r:
            cnts+=1
        return cnts
    
    rand=[3986840, 9105399, 9295665, 5185430, 9481084, 6286642, 4509520, 8680737, 7663262, 3911483, 2905903, 8829326, 3632860, 3556701, 1943314, 4147565, 6945365, 9156375, 8569604, 3518362, 9247224, 9907745, 8041336] #, 5294215, 6148921, 7892242, 2008293, 7240960, 3406413, 1685961]
    rand=rand[:20]
    
    allans=[]
    for _ in range(q):
        l,r=readIntArr()
        l-=1
        r-=1
        total=r-l+1
        ans=1
        for ran in rand:
            randomIdx=l+ran%(r-l+1)
            cnts=getCnts(l,r,a[randomIdx])
            diff=total-cnts
            ans2=1+total-(diff*2+1)
            if ans2>ans:
                ans=ans2
                break
        allans.append(ans)
    multiLineArrayPrint(allans)
    
    return

import sys
input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
# input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS.
 
def oneLineArrayPrint(arr):
    print(' '.join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
    print('\n'.join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
    print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))
 
def readIntArr():
    return [int(x) for x in input().split()]
# def readFloatArr():
#     return [float(x) for x in input().split()]

def makeArr(defaultVal,dimensionArr): # eg. makeArr(0,[n,m])
    dv=defaultVal;da=dimensionArr
    if len(da)==1:return [dv for _ in range(da[0])]
    else:return [makeArr(dv,da[1:]) for _ in range(da[0])]
 
def queryInteractive(x,y):
    print('? {} {}'.format(x,y))
    sys.stdout.flush()
   ...