//KZNS
#include <fstream>
#include <map>
using namespace std;
//
ifstream fin ("numquery.in");
ofstream fout ("numquery.out");
const int Nmax = 40003;
//
int main() {
int N, M;
int A[Nmax];
fin >> N >> M;
for (int i = 1; i <= N; i++)
fin >> A[i];
int a, b;
map<int, int> mp;
map<int, int> ::iterator mpi;
for (int i = 0; i < M; i++) {
fin >> a >> b;
mp.clear();
for (int i = a; i <= b; i++)
mp[A[i]]++;
a = 0;
b = 0;
for (mpi = mp.begin(); mpi != mp.end(); mpi++) {
if (mpi->second > a) {
a = mpi->second;
b = mpi->first;
}
}
fout << b << endl;
}
return 0;
}
//UBWH