//Solution by Tima
#include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
using namespace std;
const int N = int(3e5) + 12, mod = int(1e9) + 7, K = 450;
ll ans[N], d[K + 5][K + 5];
int n, m, a[N], b[N],c[N], cn, L[N], R[N];
int lastq[N], Nx[N], Pv[N], first[K + 5][K + 5], last[K + 5][K + 5];
int p[N], pn;
pair<int, int> A[N], B[N];
int nxt[N], prv[N];
vector <int> del[N];
void calc(int l,int r){
pn = 0;
for(int i = l; i <= r; i++){
p[++pn] = a[i];
}
sort(p + 1, p + pn + 1);
pn = unique(p + 1, p + pn + 1) - p - 1;
for(int i = l; i <= r; i++){
b[i] = lower_bound(p + 1, p + pn + 1, a[i]) - p;
del[b[i]].pb(i);
}
p[pn + 1] = cn + 1;
memset(d, 0, sizeof(d));
memset(last, 0, sizeof(last));
memset(first, 0, sizeof(first));
for(int x = 1, ls; x <= pn; x++){
int y = pn;
ls = 0;
ll cur = 0;
for(int i = l; i <= r; i++){
if(p[x] <= a[i] && a[i] <= p[y]){
nxt[ls] = i;
prv[i] = ls;
if(ls){
cur += abs(a[i] - a[ls]);
}
ls = i;
}
}
nxt[ls] = n + 1, prv[n + 1] = ls;
d[x][y] = cur;
if(ls != 0) {
first[x][y] = a[nxt[0]];
last[x][y] = a[ls];
}
while(y > x){
for(int i : del[y]){
int l = prv[i],r = nxt[i];
if(l > 0) cur -= (a[i] - a[l]);
if(r <= n) cur -= (a[i] - a[r]);
if(l > 0 && r <= n) cur += abs(a[l] - a[r]);
nxt[l] = r, prv[r] = l;
}
y--;
d[x][y] = cur;
first[x][y] = a[nxt[0]], last[x][y] = a[prv[n + 1]];
}
}
int it = pn + 1;
for (int i = m; i >= 1; --i) {
while (it - 1 > 0 && p[it - 1] >= A[i].first) --it;
Nx[A[i].second] = it;
}
it = 0;
for (int i = 1; i <= m; ++i) {
while (it + 1 <= pn && p[it + 1] <= B[i].first) ++it;
Pv[B[i].second] = it;
}
for(int i = 1,x,y; i <= m; i++){
x = Nx[i], y = Pv[i];
ans[i] += d[x][y];
if(last[x][y] != 0){
if(lastq[i] != 0){
ans[i] += abs(lastq[i] - first[x][y]);
}
lastq[i] = last[x][y];
}
}
for(int i = 1; i <= pn; i++) del[i].clear();
}
int main () {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++){
scanf("%d", &a[i]);
}
for(int i = 1; i <= m; i++){
scanf("%d%d", &L[i], &R[i]);
A[i] = {L[i], i}, B[i] = {R[i], i};
}
sort(A + 1, A + m + 1);
sort(B + 1, B + m + 1);
for(int i = 1; i <= n; i += K){
calc(i, min(i + K - 1,n));
}
for(int i = 1; i <= m; i++){
printf("%lld\n", ans[i]);
}
return 0;
}
Ly9Tb2x1dGlvbiBieSBUaW1hCiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgogCiNkZWZpbmUgZiBmaXJzdAojZGVmaW5lIHMgc2Vjb25kCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgdWxsIHVuc2lnbmVkIGxvbmcgbG9uZwojZGVmaW5lIG1wIG1ha2VfcGFpcgojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIHZpIHZlY3RvciA8aW50PgojZGVmaW5lIGxkIGxvbmcgZG91YmxlCiNkZWZpbmUgcGlpIHBhaXI8aW50LCBpbnQ+CiNkZWZpbmUgeTEgc2RhCiAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsgICAgCmNvbnN0IGludCBOID0gaW50KDNlNSkgKyAxMiwgbW9kID0gaW50KDFlOSkgICsgNywgSyA9IDQ1MDsgCgpsbCBhbnNbTl0sIGRbSyArIDVdW0sgKyA1XTsKaW50IG4sIG0sIGFbTl0sIGJbTl0sY1tOXSwgY24sIExbTl0sIFJbTl07CmludCBsYXN0cVtOXSwgTnhbTl0sIFB2W05dLCBmaXJzdFtLICsgNV1bSyArIDVdLCBsYXN0W0sg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