text: 
  //JOI bus
  //answer static queries of the max value of freq[x] * x in a range
  //poppable mo's
  
  
  //misaka will carry me to master
  #include <iostream>
  #include <cstdio>
  #include <cstring>
  #include <cmath>
  #include <utility>
  #include <cassert>
  #include <algorithm>
  #include <vector>
  #include <functional>
  #include <numeric>
  #include <set>
  #include <map>
  
  #define ll long long
  #define lb long double
  #define sz(vec) ((int)(vec.size()))
  #define all(x) x.begin(), x.end()
  #define pb push_back
  #define mp make_pair
  #define kill(x, s) {int COND = x; if(COND){ cout << s << "\n"; return ; }}
  
  const lb eps = 1e-9;
  const ll mod = 1e9 + 7, ll_max = 1e18;
  //const ll mod = (1 << (23)) * 119 +1, ll_max = 1e18;
  const int MX = 1e5 +10, int_max = 0x3f3f3f3f;
  
  using namespace std;
  
  const int magic = 3, magic2 = MX/magic;
  
  int bl(int x){
  	return x/magic;
  }
  
  struct qq{
  	int l, r, ind;
  	//[l, r]
  	qq(){}
  	qq(int a, int b, int c){ l =a, r = b, ind = c; }
  	bool operator < (const qq& b) const{
  		if(bl(l) != bl(b.l)) return l < b.l;
  		return r < b.r;
  	}
  };
  
  vector<qq> queries;
  
  ll oup [MX];
  int arr[MX];
  int freq[MX];
  int n, q;
  
  vector<int> srt;
  
  int gind(int x){
  	return lower_bound(all(srt), x) - srt.begin();
  }	
  
  void mo(){
  	sort(all(queries));
  	static vector<qq> adj[MX];
  	for(const auto& e : queries){
  		adj[bl(e.l)].pb(e);
  		assert(e.r >= (bl(e.l)+1)*magic);
  	}
  	for(int i = 0; i*magic<=n; i++){
  		static ll st[MX];
  		int ind = 0;
  		int r = (i+1)*magic, l = r;
  		for(const auto& e : adj[i]){
  			while(r <= e.r){
  				freq[arr[r]]++;
  				ind++;
  				st[ind] = max(st[ind-1], 1ll*srt[arr[r]]*freq[arr[r]]);
  				r++;
  			}	
  			while(l > e.l){
  				l--;
  				freq[arr[l]]++;
  				ind++;
  				st[ind] = max(st[ind-1], 1ll*srt[arr[l]]*freq[arr[l]]);
  			}	
  			oup[e.ind] = st[ind];
  			while(l < (i+1)*magic){
  				freq[arr[l]]--;
  				st[ind] = 0;
  				ind--;
  				l++;
  			}
  		}
  		memset(st, 0, sizeof(st));
  		memset(freq, 0, sizeof(freq));
  	}
  }
  
  void solve(){
  	cin >> n >> q;
  	for(int i = 1; i<=n; i++){
  		cin >> arr[i];
  		srt.pb(arr[i]);
  	}
  	sort(all(srt));
  	srt.resize(unique(all(srt)) - srt.begin());
  	
  	for(int i = 1; i<=n; i++) arr[i] = gind(arr[i]);
  
  	for(int i = 1; i<=q; i++){
  		int a, b;
  		cin >> a >> b;
  		if(b - a <= magic+1){
  			ll ans = 0;
  			for(int i = a; i<=b; i++){
  				freq[arr[i]]++;
  				ans = max(ans, 1ll*srt[arr[i]]*freq[arr[i]]);
  			}
  			oup[i] = ans;
  			for(int i =a; i<=b; i++) freq[arr[i]] = 0;
  		}else{
  			queries.pb(qq(a, b, i));
  		}
  	}
  	mo();
  	for(int i = 1; i<=q; i++){
  		cout << oup[i] << "\n";
  	}
  }
  
  int main(){
    cin.tie(0) -> sync_with_stdio(0);
  
    int T = 1;
    //cin >> T;
    for(int i = 1; i<=T; i++){
  		solve();
  	}
    return 0;
  }
  
  
  
  