#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("rmq.in");
ofstream fout("rmq.out");
/*
const int oo = INT32_MAX;
const int N = 500010;
int n, m, o, a, b;
int input[N], segTree[4 * N + 10];
void constructTree(int input[], int segTree[], int low, int high, int pos)
{
if (low == high)
{
segTree[pos] = input[low];
return;
}
int mid = (low + high) / 2;
// if (pos <= mid)
constructTree(input, segTree, low, mid, 2 * pos + 1);
// else
constructTree(input, segTree, mid + 1, high, 2 * pos + 2);
segTree[pos] = min(segTree[2 * pos + 1], segTree[2 * pos + 2]);
}
int rangeMinQuery(int segTree[], int Qlow, int Qhigh, int low, int high, int pos)
{
if (Qlow <= low && Qhigh >= high) // total overlap
return segTree[pos];
if (Qlow > high || Qhigh < low) // no overlap
return oo;
int mid = (low + high) / 2;
return min(rangeMinQuery(segTree, Qlow, Qhigh, low, mid, 2 * pos + 1),
rangeMinQuery(segTree, Qlow, Qhigh, mid + 1, high, 2 * pos + 2)); // double overlap
}
int main()
{
fin >> n >> m;
for (int i = 0; i < n; i++)
fin >> input[i];
for (int i = 0; i < 4 * n; i++)
segTree[i] = oo;
constructTree(input, segTree, 0, n - 1, 0);
for (int i = 0; i < 4 * n; i++)
cout << segTree[i] << " ";
for (; m != 0; m--)
{
fin >> a >> b;
fout << rangeMinQuery(segTree, a - 1, b - 1, 0, n - 1, 0) << '\n';
}
return 0;
}
*/
const int N = 100010;
int n,m,x,y,l,dif,shift;
int lg[N],a[N];
int rmq[20][N];
int main()
{
fin>>n>>m;
for(int i=1;i<=n;i++)
fin>>a[i];
for(int i=2;i<=n;i++)
lg[i]=lg[i/2] + 1;
for(int i=1;i<=n;i++)
rmq[0][i] = a[i];
for(int i=1;i<=n;i++)
for(int j=1;j<=n - (1<<i) + 1;j++)
{
l = 1<<(i-1);
rmq[i][j] = min(rmq[i-1][j],rmq[i-1][j+1]);
}
for(int i=1;i<=m;i++)
{
fin>>x>>y;
dif = y-x+1;
l = lg[dif];
shift = dif - (1<<l);
fout<<min(rmq[l][x],rmq[l][x+shift])<<'\n';
}
}