#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30);
const int mod = (int)1e9 + 7;
int a[100100];
int b[100100];
int n, q;
int dp[100100];
long long calc(int len) {
  vector<int> st;
  long long ans = 0;
  long long cur = 0;
  vector<long long> ad;
  for (int i = 1; i < len; i++) {
    while (st.size() > 0 &&
           abs(b[i] - b[i - 1]) >= abs(b[st.back()] - b[st.back() - 1])) {
      cur -= ad.back() * 1ll * abs(b[st.back()] - b[st.back() - 1]);
      st.pop_back();
      ad.pop_back();
    }
    if (st.size()) {
      ad.push_back(i - st.back());
      cur += ad.back() * 1ll * abs(b[i] - b[i - 1]);
    } else {
      ad.push_back(i);
      cur += ad.back() * 1ll * abs(b[i] - b[i - 1]);
    }
    ans += cur;
    st.push_back(i);
  }
  return ans;
}
int main() {
  cin >> n >> q;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0, l, r; i < q; i++) {
    cin >> l >> r;
    for (int j = l - 1; j < r; j++) b[j - l + 1] = a[j];
    cout << calc(r - l + 1) << "\n";
  }
  return 0;
}
