#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
#include<cstring>
#include<set>
#include<iterator>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<cmath>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<iomanip>
//#include<unordered_set>
using namespace std;
#define lowbit(x) x&(-x)
typedef long long ll;
typedef pair<int, int> P;
const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
int block_size, num;
int bel[N], R[N];
ll cnt1[N], cnt2[N], a[N], b[N];
ll Ans[N];
struct Query
{
int l, r, id;
Query(int l = 0, int r = 0, int id = 0) :l(l), r(r), id(id) {}
bool operator < (const Query &a)const
{
if (bel[l] != bel[a.l])
return bel[l] < bel[a.l];
else
return r < a.r;
}
}q[N];
int l = 1, r = 0;
ll ans = 0;
inline void update(int pos)
{
cnt1[b[pos]]++;
ans = max(ans, cnt1[b[pos]] * a[pos]);
}
inline void del(int pos)
{
cnt1[b[pos]]--;
}
vector<ll> v;
int main()
{
int n, m;
scanf("%d%d", &n, &m);
block_size = sqrt(n);
int num = n / block_size;
if (n%block_size)
num++;
for (int i = 1; i <= num; i++)
R[i] = min(i*block_size, n);
for (int i = 1; i <= n; i++)
{
scanf("%lld", &a[i]);
v.push_back(a[i]);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for (int i = 1; i <= n; i++)
{
b[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
bel[i] = (i - 1) / block_size + 1;
}
int x, y;
int tot = 0;
for (int i = 1; i <= m; i++)
{
scanf("%d%d", &x, &y);
q[++tot] = Query(x, y, i);
}
sort(q + 1, q + tot + 1);
int now = bel[q[1].l];
l = R[now] + 1, r = R[now];
for (int i = 1; i <= tot; i++)
{
if (bel[q[i].l] != now)
{
for (int j = 1; j <= n; j++)
{
cnt1[j] = 0;
}
now = bel[q[i].l];
l = R[now] + 1, r = R[now];
ans = 0;
}
if (bel[q[i].l] == bel[q[i].r])
{
ll temp = 0;
for (int j = q[i].l; j <= q[i].r; j++)
{
cnt2[b[j]] = 0;
}
for (int j = q[i].l; j <= q[i].r; j++)
{
cnt2[b[j]]++;
temp = max(temp, cnt2[b[j]] * a[j]);
}
Ans[q[i].id] = temp;
}
else
{
while (r < q[i].r)
update(++r);
ll temp = ans;
while (l > q[i].l)
update(--l);
Ans[q[i].id] = ans;
while (l < R[now] + 1)
del(l), l++;
ans = temp;
}
}
for (int i = 1; i <= tot; i++)
{
printf("%lld\n", Ans[i]);
}
return 0;
}