#include <iostream>
#include<cstdio>
#define inf 100000000000
using namespace std;
#define DIM 10000
char buff[DIM];
int poz=0;
void citeste(int &numar)
{
numar = 0;
//cat timp caracterul din buffer nu e cifra ignor
while (buff[poz] < '0' || buff[poz] > '9')
//daca am "golit" bufferul atunci il umplu
if (++poz == DIM)
fread(buff,1,DIM,stdin),poz=0;
//cat timp dau de o cifra recalculez numarul
while ('0'<=buff[poz] && buff[poz]<='9')
{
numar = numar*10 + buff[poz] - '0';
if (++poz == DIM)
fread(buff,1,DIM,stdin),poz=0;
}
}
int v[100001],n,m,i,x,y,tree[400004];
void constructTree(int low,int high,int poz)
{
if(low==high)
{
tree[poz]=v[low];
return;
}
int mid=(low+high)/2;
constructTree(low,mid,2*poz);
constructTree(mid+1,high,2*poz+1);
tree[poz]=min(tree[2*poz],tree[2*poz+1]);
}
int RMQ(int x,int y,int low,int high,int poz)
{
if(x<=low && y>=high)
return tree[poz];
if(x>high || y<low)
return inf;
int mid=(low+high)/2;
return min(RMQ(x,y,low,mid,2*poz),RMQ(x,y,mid+1,high,2*poz+1));
}
int main()
{
freopen("rmq.in","r",stdin);
freopen("rmq.out","w",stdout);
citeste(n);
citeste(m);
for(i=1; i<=n; i++)
citeste(v[i]);
constructTree(1,n,1);
for(i=1; i<=m; i++)
{
citeste(x);
citeste(y);
cout<<RMQ(x,y,1,n,1)<<'\n' ;
}
}