#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int Max = 100000 + 10;
int maxsum[Max][32], minsum[Max][32];
int n, q, v;
void RMQ_init()
{
for (int j = 1; (1 << j) <= n; j++)
{
for (int i = 1; i + (1 << j) - 1 <= n; i++)
{
maxsum[i][j] = max(maxsum[i][j - 1], maxsum[i + (1 << (j - 1))][j - 1]);
minsum[i][j] = min(minsum[i][j - 1], minsum[i + (1 << (j - 1))][j - 1]);
}
}
}
int RMQ(int l, int r)
{
int k = 0;
while ((1 << (k + 1)) <= (r - l + 1))
k++;
int maxn = max(maxsum[l][k], maxsum[r - (1 << k) + 1][k]);
int minn = min(minsum[l][k], minsum[r - (1 << k) + 1][k]);
return maxn - minn;
}
int main()
{
while (scanf("%d%d", &n, &q) != EOF)
{
for (int i = 1; i <= n; i++)
{
scanf("%d", &v);
minsum[i][0] = maxsum[i][0] = v;
}
RMQ_init();
while (q--)
{
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", RMQ(a, b));
}
}
system("pause");
return 0;
}