//Kaiba_Seto 20170120
//orz cjkmao
#include <math.h>
#include <stdio.h>
#include <memory.h>
#include <algorithm>
#define MaxN 100010
#define MaxS 350
#define RG register
#define inline __inline__ __attribute__((always_inline))
#define L long long
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io{
#define MaxBuf 1<<22
#define _getc() ((S==T&&(T=(S=B)+fread(B,1,MaxBuf,stdin),S==T))?0:*S++)
char B[MaxBuf],*S=B,*T=B;
template<class Type>inline void Rin(RG Type &x){
x=0;RG int c=getchar();RG bool b=0;
for(;c<48||c>57;c=getchar())
if(c==45)b=1;
for(;c>47&&c<58;c=getchar())
x=(x<<1)+(x<<3)+c-48;
if(b)x=-x;
}
};
int n,_q,a[MaxN],_reflection[MaxN],block_size,block_cnt[MaxS][MaxN],belong[MaxN],lef[MaxS],rig[MaxS];
L block_rmq[MaxS][MaxS];
struct _pair{
int first,*second;
bool operator < (const _pair &other) const {
return first < other.first;
}
}c[MaxN];
inline L query(RG int x,RG int y){
static int tmp_tim[MaxN],tmp_cnt[MaxN],T=0;
RG int _l=belong[x],_r=belong[y];
RG L res=block_rmq[_l+1][_r-1]; ++T;
if(_l == _r){
for(RG int i=x;i<=y;i++){
if(tmp_tim[a[i]] != T){
tmp_tim[a[i]]=T; tmp_cnt[a[i]]=0;
}
++tmp_cnt[a[i]];
res=dmax(res,(L) _reflection[a[i]] * tmp_cnt[a[i]]);
}
return res;
}
for(RG int i=x;i<=:: rig[_l];i++){
if(tmp_tim[a[i]] != T){
tmp_tim[a[i]]=T; tmp_cnt[a[i]]=block_cnt[_r-1][a[i]]-block_cnt[_l][a[i]];
}
++tmp_cnt[a[i]];
res=dmax(res,(L) _reflection[a[i]] * tmp_cnt[a[i]]);
}
for(RG int i=:: lef[_r];i<=y;i++){
if(tmp_tim[a[i]] != T){
tmp_tim[a[i]]=T; tmp_cnt[a[i]]=block_cnt[_r-1][a[i]]-block_cnt[_l][a[i]];
}
++tmp_cnt[a[i]];
res=dmax(res,(L) _reflection[a[i]] * tmp_cnt[a[i]]);
}
return res;
}
int main(){
io::Rin(n),io::Rin(_q);
block_size=static_cast<int>(sqrt(n)+1e-6);
for(RG int i=1;i<=n;i++)
io::Rin(c[i].first),c[i].second=&a[i];
std::sort(c+1,c+1+n);
for(RG int i=1,m=0;i<=n;i++){
if(i==1 || c[i].first != c[i-1].first)
_reflection[++m]=c[i].first;
*c[i].second=m;
}
for(RG int i=1;i<=n;i++)
belong[i]=(i-1)/block_size+1;
for(RG int i=1;i<=n;i++)
block_cnt[belong[i]][a[i]]++;
for(RG int i=1;(i-1)*block_size+1<=n;i++)
lef[i]=(i-1)*block_size+1,rig[i]=dmin(i*block_size,n);
for(RG int i=1;:: lef[i];i++)
for(RG int j=1;j<=n;j++)
block_cnt[i][j]+=block_cnt[i-1][j];
for(RG int i=1;lef[i];i++){
static int tmp_cnt[MaxN]; RG L ans=0LL;
memset(tmp_cnt,0,sizeof tmp_cnt);
for(RG int j=lef[i];j<=n;j++){
++tmp_cnt[a[j]];
ans=dmax(ans,(L) _reflection[a[j]] * tmp_cnt[a[j]]);
if(j == rig[belong[j]])
:: block_rmq[i][belong[j]]=ans;
}
}
while(_q--){
RG int x,y;
io::Rin(x),io::Rin(y);
printf("%lld\n",query(x,y));
}
fclose(stdin);
return 0;
}