#include <bits/stdc++.h>
using namespace std;
int n, q;
long long a[100005], b[100005], pre[100005], lo[100005], maxn[100005][20],
    minn[100005][20];
void build() {
  for (int i = 2; i < n + 1; i++) {
    lo[i] = lo[i / 2] + 1;
  }
  for (int i = 1; i < n + 1; i++) {
    maxn[i][0] = minn[i][0] = pre[i];
  }
  for (int i = 1; i < lo[n] + 1; i++) {
    for (int j = 1; j < n + 1; j++)
      if (j + (1 << i) - 1 <= n) {
        maxn[j][i] = max(maxn[j][i - 1], maxn[j + (1 << (i - 1))][i - 1]);
        minn[j][i] = min(minn[j][i - 1], minn[j + (1 << (i - 1))][i - 1]);
      }
  }
}
long long q_max(int l, int r) {
  long long x = lo[(r - l) + 1];
  return max(maxn[l][x], maxn[r - (1 << x) + 1][x]);
}
long long q_min(int l, int r) {
  long long x = lo[(r - l) + 1];
  return min(minn[l][x], minn[r - (1 << x) + 1][x]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n >> q;
  for (int i = 1; i < n + 1; i++) cin >> a[i];
  for (int i = 1; i < n + 1; i++) cin >> b[i];
  for (int i = 1; i < n + 1; i++) pre[i] = pre[i - 1] + b[i] - a[i];
  build();
  while (q--) {
    int l, r;
    cin >> l >> r;
    if (pre[r] != pre[l - 1])
      cout << -1 << endl;
    else if (q_min(l, r) < pre[l - 1])
      cout << -1 << endl;
    else {
      cout << q_max(l, r) - pre[l - 1] << endl;
    }
  }
}
