#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define endl "\n"
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const int N = 1e5 + 10, M = N * 2, mod = 1e9 + 7, inf = 0x3f3f3f3f, P = 131;
int dp[N][26];
int dpp[N][26];
int ask1(int l,int r){
int j=log2(r-l+1);
return max(dp[l][j],dp[r-(1<<j)+1][j]);
}
int ask2(int l,int r){
int j=log2(r-l+1);
return min(dpp[l][j],dpp[r-(1<<j)+1][j]);
}
void solve()
{
int n,m;
cin >> n >> m;
for(int i=0;i<n;i++) cin >> dp[i][0];
for(int i=0;i<n;i++) dpp[i][0]=dp[i][0];
for(int j=1;j<=log2(n);j++)
for(int i=0;i+(1<<j)-1<n;i++)
dp[i][j]=max(dp[i][j-1],dp[i+(1<<(j-1))][j-1]);
for(int j=1;j<=log2(n);j++)
for(int i=0;i+(1<<j)-1<n;i++)
dpp[i][j]=min(dpp[i][j-1],dpp[i+(1<<(j-1))][j-1]);
int l,r;
while(m--){
cin >> l >> r;
cout<<ask1(l-1,r-1)-ask2(l-1,r-1)<<endl;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
//cin >> t;
while(t --)
solve();
return 0;
}