#include <fstream>
#include <iostream>
#include <array>
#include <vector>
#include <cmath>
using namespace std;
template <typename T, int max_niv>
class rmq{
int n;
array<vector<T>, max_niv> buf;
public:
template <typename F>
rmq(const int N, F f): n(N){
buf[0].resize(n);
for(int i = 0; i < n; ++i){
buf[0][i] = f(i); }
for(int niv = 1, step = 1; niv <= max_niv; ++niv, step *= 2){
buf[niv].resize(n);
for(int i = 0; i+step < n; ++i){
buf[niv][i] = min(buf[niv-1][i], buf[niv-1][i+step]); } } }
int query(const int st, const int dr){
const int sz = dr-st+1, niv = log2(sz), step = 1<<niv;
return min(buf[niv][st], buf[niv][dr-step+1]); } };
int main(){
ifstream f("rmq.in");
int n, m;
f >> n >> m;
rmq<int, 17> r(n, [&f](const int i){
int x;
f >> x;
return x; });
ofstream g("rmq.out");
for(int i = 0, a, b; i < m; ++i){
f >> a >> b;
int rez = r.query(a-1, b-1);
g << rez << '\n'; }
return 0; }