#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
//#define s second
#define pb push_back
#define mp make_pair
#define pi pair<ll, ll>
#define sz(x) (int)((x).size())
#define all(a) (a).begin(), (a).end()
/* int f[maxn],nf[maxn],inv[maxn];
const int M=998244353;
void init(){
inv[1]=1; for (int i=2;i<maxn;i++) inv[i]=M-1ll*(M/i)*inv[M%i]%M;
f[0]=nf[0]=1; for (int i=1;i<maxn;i++) f[i]=1ll*f[i-1]*i%M,nf[i]=1ll*nf[i-1]*inv[i]%M;
}
int C(int x,int y){return 1ll*f[x]*nf[y]%M*nf[x-y]%M;}*/
const ll mod = 1e9+7;
ll n, k, m, mi, ma;
const ll N = 3e5;
void solve(){
ifstream cin("rmq.in");
ofstream cout("rmq.out");
ll q;
cin >> n >> q;
vector<ll> a, p(n + 5);
for(int i = 0; i<n; i++){
cin >> m;
a.pb(m);
}
p[1] = 0;
for(int i = 2; i<=n; i++) p[i] = p[i/2] + 1;
ll st[n][p[n]];
for(int i = 0; i<n; i++) st[i][0] = a[i];
k = 1;
for(int j = 1; j <= p[n]; j++){
for(int i = 0; i + 2*k <= n; i++){
st[i][j] = min(st[i][j - 1], st[i + k][j - 1]);
}
k += k;
}
for(int i = 0; i < q; i++){
ll x, y;
cin >> x >> y;
x--; y--;
ll l = y - x + 1;
ll r = p[l];
cout << min(st[x][r], st[y + 1 - (1<<r)][r]) << "\n";
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
// cin >> t;
while(t--) solve();
return 0;
}