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 <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) { 
    cerr << ' ' <<  p.x << ',' << p.y; return os; }
template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) { 
    for(auto x: v) os << ' ' <<  x; return os; }
template <typename T> 
ostream& operator<<(ostream& os, const set<T>& v) { 
    for(auto x: v) os << ' ' <<  x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) { 
    for(auto x: v) os << ' ' <<  x; return os; }
struct d_ {
    template<typename T> d_& operator,(const T& x) {
        cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define YES(x) cout << (x ? "YES" : "NO") << endl;
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

ll n,q;
const ll N = 3e5+7;
vll pos[N];
ll a[N];
const ll X = 40;

ll getcnt(ll l, ll r, ll x) {
    auto lit = lower_bound(all(pos[x]), l);
    auto rit = upper_bound(all(pos[x]), r);
    return rit-lit;
}

vll solve(vpll qs) {
    F(n) pos[a[i]].pb(i);
    vll ret;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    for(auto [l,r]: qs) {
        ll mxc = 0;
        ll len = r-l+1;
        REP(__,X) {
            ll pos = uniform_int_distribution<int>(l,r)(rng);
            ll cnt = getcnt(l,r,a[pos]);
            mxc = max(mxc,cnt);
        }
        ll cur = 1;
        if(mxc>(len+1)/2) {
            ll rest = len-mxc;
            cur += max(mxc-rest-1,0ll);
        }
        ret.pb(cur);
    }
    return ret;
}

void gen() {
    F(N) pos[i].clear();
    F(N) a[i]=0;
    n = rand()%30+1;
    F(n) a[i] = rand()%n;
    ll l=rand()%n;
    ll r=l+(rand()%(n-l));
    ll mxc = 0;
    F(n) {
        ll c = 0;
        FOR(j,l,r+1) c+=a[j]==i;
        mxc=max(mxc,c);
    }
    ll len = r-l+1;
    vll ref = {1ll+max(0ll, mxc-(len-mxc)-1)};
    vll ret = solve({{l,r}});
    if(ret!=ref) {
        cerr << n << ' ' << 1 << endl;
        F(n) cerr << a[i]+1 << ' ';
        cerr << endl;
        cerr<<l+1 << ' ' << r+1 << endl;
        dbg("ret",ret);
        dbg("ref",ref);
        exit(1);
    }
}

int main(void) {
    ios_base::sync_with_stdio(false);
    srand(time(0));
//     REP(_,10000) gen();
    cin >> n >> q;
    F(n) { cin >> a[i]; a[i]--; }
    vpll qs;
    F(q) {
        ll l,r; cin >> l >> r;
        l--; r--;
        qs.eb(l,r);
    }
    auto ret = solve(qs);
    for(auto i: ret) cout << i << endl;
    return 0;
}
