#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
constexpr int N = 100000;
constexpr long long A = 1000000000;
int n;
long long a[N + 10], b[N + 10];
struct ss {
  long long sum, mins, maxs;
  friend ss operator|(const ss& x, const ss& y) {
    long long nsum = x.sum + y.sum;
    long long nmins = std::min(x.mins, x.sum + y.mins);
    long long nmaxs = std::max(x.maxs, x.sum + y.maxs);
    return {nsum, nmins, nmaxs};
  }
  friend std::ostream& operator<<(std::ostream& os, const ss& x) {
    os << "[" << x.sum << "," << x.mins << "," << x.maxs << "]";
    return os;
  }
} s[N * 4 + 10];
int lson(int i) { return i << 1; }
int rson(int i) { return i << 1 | 1; }
void push_up(int i) {
  int ls = lson(i), rs = rson(i);
  s[i] = (s[ls] | s[rs]);
  return;
}
void build(int i, int l, int r) {
  if (l == r) {
    s[i].sum = s[i].mins = s[i].maxs = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(lson(i), l, mid);
  build(rson(i), mid + 1, r);
  push_up(i);
  return;
}
ss query(int i, int l, int r, int q_l, int q_r) {
  const long long inf = 0x3f3f3f3f3f3f3f3f;
  if (q_l <= l && r <= q_r)
    return s[i];
  else if (q_l > r || q_r < l)
    return {0, inf, -inf};
  int mid = (l + r) >> 1;
  ss ansl = query(lson(i), l, mid, q_l, q_r);
  ss ansr = query(rson(i), mid + 1, r, q_l, q_r);
  return (ansl | ansr);
}
int q;
int main() {
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) cin >> b[i], a[i] = b[i] - a[i];
  build(1, 1, n);
  for (int i = 1; i <= q; ++i) {
    int l, r;
    cin >> l >> r;
    ss qs = query(1, 1, n, l, r);
    if (qs.mins < 0 || qs.sum != 0)
      cout << -1 << endl;
    else
      cout << qs.maxs << endl;
  }
  return 0;
}
