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].
//*******************************************************************
//              author of this code is : horcrux903
//*******************************************************************
//        THERE IS ALWAYS A WAY TO GO IF YOU LOOK FOR IT
//*******************************************************************

//*******************************************************************

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

#define ll               long long int
#define ull              unsigned long long int
#define ld               long double
#define F(i,a,n)         for(int i=a;i<n;i++)
#define FO(i,a,n)        for(int i=n-1;i>=a;i--)
#define fast()           ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl             "\n"
#define set0(a)          memset(a,0,sizeof(a))
#define set1(a)          memset(a,-1,sizeof(a))
#define setf(a)          memset(a,false,sizeof(a))
#define pb(i)            push_back(i)
#define len(s)           s.length()
#define mp               make_pair
#define PI               3.141592653589793238462643383279
#define ss               second
#define ff               first
#define vll              vector<int>
#define vpair            vector<pair<int,int>>
#define vvpair           vector<vector<pair<long long int,long long int>>>
const int INF = 1e18L + 5;

using namespace std;

// using namespace __gnu_pbds;
// template <typename T>
// using ordered_Set = tree<T, null_type, less<T>,
// rb_tree_tag, tree_order_statistics_node_update>;

//*******************************************************************

long long int M = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void input()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

//********************************************************************


// ll gcd(ll a, ll b)
// {
//     if (b == 0)
//         return a;
//     return gcd(b, a % b);
// }

// ll lcm(ll a, ll b)
// {
//     return (a * b) / gcd(a, b);
// }


//********************************************************************


// ll power(ll x, ll y, ll mod)
// {
//     ll ans = 1;

//     x = x % mod;

//     while (y > 0)
//     {
//         if (y & 1)
//             ans = ((ans % mod) * (x % mod)) % mod;

//         y = y >> 1;
//         x = ((x % mod) * (x % mod)) % mod;
//     }
//     return ans;
// }


//********************************************************************


// ll f[200006];

// ll ncr(ll n, ll r)
// {
//     if (n < r)
//     {
//         return 0;
//     }
//     ll num = f[n];
//     ll temp = (f[r] * (f[n - r])) % M;
//     ll ans = num * power(temp, M - 2, M);
//     return (ans % M);
// }


//********************************************************************


// ll bs(vll &arr, ll target, ll end)
// {
//     ll start = 0;

//     ll ans = -1;

//     while (start <= end)
//     {
//         ll mid = (start + end) / 2;

//         if (arr[mid] <= target)
//             start = mid + 1;

//         else
//         {
//             ans = mid;
//             end = mid - 1;
//         }
//     }
//     return ans;
// }


//*******************************************************************


// bool prime[1000006];
// vll v;

// void SieveOfEratosthenes(int n)
// {
//     memset(prime, true, sizeof(prime));

//     prime[0] = prime[1] = false;

//     for (int p = 2; p * p <= n; p++)
//     {
//         if (prime[p] == true)
//         {
//             for (int i = p * p; i <= n; i += p)
//                 prime[i] = false;
//         }
//     }

//     for (int p = 2; p <= n; p++)
//         if (prime[p])
//             v.pb(p);
// }


//*******************************************************************


void solve()
{
    ll n, q;
    cin >> n >> q;

    srand(0);

    ll a[n + 1];

    vector<vector<ll>> v(n + 1);

    F(i, 1, n + 1)
    {
        cin >> a[i];
        v[a[i]].pb(i);
    }

    while (q--)
    {
        ll l, r;
        cin >> l >> r;

        set<ll> s;

        F(i, 0, 20)
        {
            ll p = l + rand() % (r - l + 1), q = r - rand() % (r - l + 1);;
            s.insert(a[p]);
            s.insert(a[q]);
        }

        ll ans = 1;

        for (auto x : s)
        {
            ll f = upper_bound(v[x].begin(), v[x].end(), r) - lower_bound(v[x].begin(), v[x].end(), l);
            ans = max(ans, 2 * f - (r - l + 1));
        }
        cout << ans << endl;
    }
}


//*******************************************************************


int main()
{
    fast()
    input();                                  //comment this during codejam/kickstart

    // SieveOfEratosthenes(1000006);

    // f[0] = 1;

    // F(i, 1, 2e5 + 1)
    // {
    //     f[i] = (f[i - 1] * i) % M;
    // }

    int t = 1, i = 1;
    // cin >> t;

    while (t--)
    {
        // cout << "Case #" << i << ": ";      //only during google contest
        // i++;                                //only during google contest
        solve();
        cout << endl;
    }
}


//*******************************************************************