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].
 // Lights will guide you home

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll int
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define bug(x) printf("BUG %lld\n", x
#define pb push_back

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

struct node
{
    ll l, r, id;
};

const ll lim = 300005;

node q[lim];
ll ans[lim];
ll freq[300006];
ll mx[300006];
ll arr[lim];
ll cnt;
ll block = 916;

bool comp(node a, node b)
{
    ll ablc = a.l / block;
    ll bblc = b.l / block;

    if(ablc != bblc)
    {
        return ablc < bblc;
    }

    if(ablc % 2 == 0)
    {
        return a.r < b.r;
    }
    else
    {
        return a.r > b.r;
    }
}


void add(ll x)
{
	freq[arr[x]]++;
	mx[freq[arr[x]]]++;

	cnt = (freq[arr[x]] > cnt ? freq[arr[x]]: cnt);
}

void rem(ll x)
{
	mx[freq[arr[x]]]--;
	freq[arr[x]]--;

	cnt -= (mx[cnt] == 0? 1: 0);
}


// q[i].blc = l / ssq;  /// block count

/*
	l = 1, r = 0, cnt = 0;

    while(l > q[i].l) add(--l);
    while(r < q[i].r) add(++r);
    while(l < q[i].l) rem(l++);
    while(r > q[i].r) rem(r--);
*/


int main()
{
    ll i, j, k, l, m, n, r;
    ll testcase;
    ll in;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    fastio;
    while(cin >> n >> m)
    {
        for(ll i = 1; i <= n; i++) cin >> arr[i];

        block = sqrt(n) - 10;

        block = max(1, block);

        for(ll i = 1; i <= m; i++)
        {
            cin >> q[i].l >> q[i].r;
            q[i].id = i;
        }

        sort(q + 1, q + 1 + m, comp);

        l = 0, r = 0;
        cnt = 0;

        for(ll i = 1; i <= m; i++)
        {
            while(l > q[i].l) add(--l);
            while(r < q[i].r) add(++r);
            while(l < q[i].l) rem(l++);
            while(r > q[i].r) rem(r--);

            ans[q[i].id] = cnt * 2 - (r - l + 1);
        }

        for(ll i = 1; i <= m; i++)
        {
            cout << max(1, ans[i]) << "\n";
        }
    }


}


