#include <bits/stdc++.h>
#pragma GCC optimize("O3,inline")
using namespace std;
FILE* fin = fopen("rmq.in", "r");
FILE* fout = fopen("rmq.out", "w");
int rmq[362000]; int N,x,y,M;
void insert(int val, int pos, int posInRMQ, int st, int dr){
if(st == dr){
rmq[posInRMQ] = val;
return;
}
if(pos <= ((st+dr)>>1)){
insert(val, pos, posInRMQ*2, st, ((st+dr)>>1));
rmq[posInRMQ] = min(rmq[posInRMQ*2], rmq[posInRMQ*2 + 1]);
}
if(pos >= ((st+dr)>>1)){
insert(val, pos, posInRMQ*2 + 1, ((st+dr)>>1)+1, dr);
rmq[posInRMQ] = min(rmq[posInRMQ*2], rmq[posInRMQ*2 + 1]);
}
}
int getMinValue(int x, int y, int pos, int st = 1, int dr = N){
if(x <= st && y >= dr)
return rmq[pos];
else if(st <= y && dr >= x)
return min(getMinValue(x,y,2*pos,st,((st+dr)>>1)),getMinValue(x,y,2*pos+1,((st+dr)>>1)+1,dr));
return INT_MAX;
}
int main(){
fscanf(fin, "%d", &N);
fscanf(fin, "%d", &M);
ios::sync_with_stdio(false);
for(int i = 0; i < N; ++i){
fscanf(fin, "%d", &x);
insert(x, i, 1, 0, N-1);
}
for(int i = 0; i < M; ++i){
fscanf(fin, "%d", &x);
fscanf(fin, "%d", &y);
fprintf(fout, "%d", getMinValue(x,y,1));
fprintf(fout, "%c", '\n');
}
}