#include<iostream>
#include<fstream>
using namespace std;
ifstream f("rmq.in");
ofstream g("rmq.out");
int A[500001];
void update(int n, int l, int r, int pos, int val)
{
if(l==r)
{
r=pos;
A[n]=val;
return;
}
int mid;
mid=(l+r)/2;
if(pos<=mid) update(2*n, l ,mid, pos, val);
else update(2*n+1, mid+1, r, pos, val);
A[n]=min(A[2*n], A[2*n+1]);
}
int query(int n, int l, int r, int a, int b)
{
int v1=100001, v2=100001;
if(a<=l && r<=b) return A[n];
int mid;
mid=(l+r)/2;
if(a<=mid)
{
v1=query(2*n, l, mid, a, b);
}
if(b>mid)
{
v2=query(2*n+1, mid+1, r, a, b);
}
if(v1<=v2)
return v1;
else return v2;
}
int main()
{
int N, M, x,operatie,a,b;
f>>N>>M;
for(int i=1;i<=N;i++)
{f>>x; update(1,1,N,i,x);}
for(int i=1;i<=M;i++)
{
f>>a>>b;
g<<query(1,1,N,a,b);
g<<'\n';
}
return 0;
}