#include <bits/stdc++.h>
using namespace std;
long long good_rand() { return rand() * RAND_MAX + rand(); }
long long high_rand() {
  long long ran = rand() * RAND_MAX;
  ran *= RAND_MAX;
  ran += rand() * RAND_MAX + rand();
  return ran;
}
template <class A>
class myvector : public std::vector<A> {
 public:
  A &operator[](int pos) {
    if (pos < 0) pos = 0;
    while (this->size() <= pos) {
      this->push_back({});
    }
    return std::vector<A>::operator[](pos);
  }
  void print(bool b = false) {
    unsigned int si = this->size();
    if (b) std::cout << si << std::endl;
    for (unsigned int i = 0; i < si; ++i) {
      std::cout << this->operator[](i) << " ";
    }
  }
  void printendl(bool b = false) {
    print(b);
    std::cout << std::endl;
  }
  void good_random_shuffle() {
    unsigned int si = this->size();
    for (unsigned int i = 0; i < si - 1; ++i) {
      unsigned int j = good_rand() % (si - i);
      j += i;
      swap(this->operator[](i), this->operator[](j));
    }
  }
  template <class B>
  void read(B &n, bool b = false) {
    if (b) std::cin >> n;
    for (int i = 0; i < n; ++i) {
      std::cin >> this->operator[](i);
    }
  }
  void push_to(int pos, int val) {
    while (this->size() > pos) {
      int newval = this->operator[](pos);
      this->operator[](pos) = val;
      val = newval;
      ++pos;
    }
    this->operator[](pos) = val;
  }
};
template <class A>
class myqueue : public std::queue<A> {
 public:
  A front() const {
    if (this->empty()) return {};
    return std::queue<A>::front();
  }
  A top() const { return front(); }
  void pop() {
    if (this->empty()) return;
    std::queue<A>::pop();
  }
  A take() {
    A a = this->front();
    this->pop();
    return a;
  }
  void print(bool b = false) {
    while (!this->empty()) {
      std::cout << take() << " ";
    }
  }
  void printendl(bool b = false) {
    print(b);
    std::cout << std::endl;
  }
};
template <class A, class B = std::less<typename std::vector<A>::value_type>>
class mypriority_queue : public std::priority_queue<A, std::vector<A>, B> {
 public:
  A top() const {
    if (this->empty()) return {};
    return std::priority_queue<A, std::vector<A>, B>::top();
  }
  void pop() {
    if (this->empty()) return;
    std::priority_queue<A, std::vector<A>, B>::pop();
  }
  A take() {
    A a = this->top();
    this->pop();
    return a;
  }
  void print(bool b = false) {
    while (!this->empty()) {
      std::cout << take() << " ";
    }
  }
  void printendl(bool b = false) {
    print(b);
    std::cout << std::endl;
  }
};
class modll {
  static const long long mod = 998244353;
  long long modvalue = 0;

 public:
  modll() { this->modvalue = 0; }
  modll(int x) { this->modvalue = x % mod; }
  modll(long long x) { this->modvalue = x % mod; }
  modll(const modll &x) { this->modvalue = x.modvalue; }
  long long getmodvalue() const { return modvalue; }
  static long long modpow(long long z, long long u) {
    if (u == 0) return 1;
    if (u == 1) return z;
    if (u % 2 == 0) {
      long long sa = modpow(z, u / 2);
      return (sa * sa) % mod;
    }
    return (z * modpow(z, u - 1)) % mod;
  }
  static modll fastpow(long long z, long long u) {
    modll a = modpow(z, u);
    return a;
  }
  static modll fact(long long z) {
    modll a = 1;
    for (long long i = 2; i <= z; ++i) {
      a *= i;
    }
    return a;
  }
  static modll choose(long long n, long long k) {
    modll a = 1;
    for (long long i = n; n - i + 1 <= k; --i) {
      modll b = i;
      a = a * b;
    }
    for (long long i = 2; i <= k; ++i) {
      modll b = i;
      a = a / b;
    }
    return a;
  }
  long long rec() const { return modll::modpow(modvalue, mod - 2); }
  modll operator+(const modll &x) const {
    modll a;
    a.modvalue = (this->modvalue + x.modvalue) % mod;
    return a;
  }
  modll operator-(const modll &x) const {
    modll a;
    a.modvalue = (mod + this->modvalue - x.modvalue) % mod;
    return a;
  }
  modll operator*(const modll &x) const {
    modll a;
    a.modvalue = (this->modvalue * x.modvalue) % mod;
    return a;
  }
  modll operator/(const modll &x) const {
    modll a;
    if (x.modvalue == 0) return a;
    a.modvalue = (this->modvalue * x.rec()) % mod;
    return a;
  }
  template <class A>
  modll operator+(A x) const {
    if (x < 0) return this->operator-(-x);
    modll a;
    a.modvalue = (this->modvalue + x % mod) % mod;
    return a;
  }
  template <class A>
  modll operator-(A x) const {
    if (x < 0) return this->operator+(-x);
    modll a;
    a.modvalue = (this->modvalue - (x % mod) + mod) % mod;
    return a;
  }
  template <class A>
  modll operator*(A x) const {
    if (x < 0) {
      long long y = x / mod;
      y *= mod;
      y = x - y;
      x = y;
    }
    x %= mod;
    modll a;
    a.modvalue = (this->modvalue * x) % mod;
    return a;
  }
  template <class A>
  modll operator/(A x) const {
    if (x < 0) {
      long long y = x / mod;
      y *= mod;
      y = x - y;
      x = y;
    }
    x %= mod;
    modll a;
    if (x == 0) return a;
    modll b = x;
    a = *this / b;
    return a;
  }
  void operator=(modll x) { this->modvalue = x.modvalue; }
  template <class A>
  void operator=(A x) {
    this->modvalue = x % mod;
  }
  bool operator==(modll x) const { return (this->modvalue == x.modvalue); }
  template <class A>
  bool operator==(A x) const {
    return (this->modvalue == x);
  }
  bool operator<(modll x) const { return (this->modvalue < x.modvalue); }
  template <class A>
  bool operator<(A x) const {
    return (this->modvalue < x);
  }
  bool operator>(modll x) const { return (this->modvalue > x.modvalue); }
  template <class A>
  bool operator>(A x) {
    return (this->modvalue > x);
  }
  bool operator<=(modll x) const { return (this->modvalue <= x.modvalue); }
  template <class A>
  bool operator<=(A x) const {
    return (this->modvalue <= x);
  }
  bool operator>=(modll x) const { return (this->modvalue >= x.modvalue); }
  template <class A>
  bool operator>=(A x) const {
    return (this->modvalue >= x);
  }
  void operator+=(const modll &x) {
    this->modvalue += x.modvalue;
    this->modvalue %= mod;
  }
  template <class A>
  void operator+=(A x) {
    if (x < 0) this->operator+=(-1 * x);
    this->modvalue += x % mod;
    if (modvalue < 0) {
      this->modvalue *= -1;
      if (modvalue % mod == 0)
        modvalue = 0;
      else
        modvalue = mod - (modvalue % mod);
    }
    this->modvalue %= mod;
  }
  void operator-=(const modll &x) {
    this->modvalue -= x.modvalue;
    while (this->modvalue < 0) this->modvalue += mod;
    this->modvalue %= mod;
  }
  template <class A>
  void operator-=(A x) {
    if (x < 0) this->operator+=(-1 * x);
    this->modvalue -= x % mod;
    if (modvalue < 0) {
      this->modvalue *= -1;
      if (modvalue % mod == 0)
        modvalue = 0;
      else
        modvalue = mod - (modvalue % mod);
    }
    this->modvalue %= mod;
  }
  void operator*=(const modll &x) {
    this->modvalue *= x.modvalue;
    this->modvalue %= mod;
  }
  template <class A>
  void operator*=(A x) {
    bool neg = false;
    if (x < 0) {
      neg = true;
      x *= -1;
    }
    this->modvalue *= x % mod;
    if (modvalue < 0) {
      this->modvalue *= -1;
      if (modvalue % mod == 0)
        modvalue = 0;
      else
        modvalue = mod - (modvalue % mod);
    }
    this->modvalue %= mod;
    if (neg) {
      this->modvalue = mod - modvalue;
      this->modvalue %= mod;
    }
  }
  void operator/=(const modll &x) {
    if (x.modvalue == 0) {
      this->modvalue = 0;
      return;
    }
    this->modvalue = this->modvalue / x.modvalue;
    this->modvalue %= mod;
  }
  template <class A>
  void operator/=(A x) {
    bool neg = false;
    if (x < 0) {
      neg = true;
      x *= -1;
    }
    modll se = x % mod;
    this->operator/=(se);
    if (modvalue < 0) {
      this->modvalue *= -1;
      if (modvalue % mod == 0)
        modvalue = 0;
      else
        modvalue = mod - (modvalue % mod);
    }
    this->modvalue %= mod;
    if (neg) {
      this->modvalue = mod - modvalue;
      this->modvalue %= mod;
    }
  }
  modll operator++() {
    modvalue++;
    if (modvalue == mod) modvalue = 0;
  }
  modll operator--() {
    modvalue--;
    if (modvalue < 0) modvalue += mod;
  }
  void print() const { std::cout << this->modvalue; }
  void printspace() const { std::cout << this->modvalue << " "; }
  void printendl() const { std::cout << this->modvalue << std::endl; }
};
string yes = "YES\n";
string no = "NO\n";
myvector<long long> v;
myvector<long long> a;
myvector<long long> b;
long long n, m, k, l, r;
mypriority_queue<long long, std::greater<long long>> pq;
myqueue<long long> q;
set<long long> s;
long long sum[100005];
long long as[100005];
typedef struct node {
  long long sum;
  long long prefix;
} node;
node tree[4 * 100005];
node tree2[4 * 100005];
void build(long long idx, long long start, long long end) {
  if (start == end) {
    tree[idx].sum = v[start] * long long(-1);
    tree[idx].prefix = v[start] * long long(-1);
  } else {
    long long mid = (start + end) / 2;
    build(2 * idx + 1, start, mid);
    build(2 * idx + 2, mid + 1, end);
    tree[idx].sum = tree[2 * idx + 1].sum + tree[2 * idx + 2].sum;
    tree[idx].prefix = max(tree[2 * idx + 1].prefix,
                           tree[2 * idx + 1].sum + tree[2 * idx + 2].prefix);
  }
}
node query(long long idx, long long start, long long end, long long l,
           long long r) {
  node result;
  result.sum = result.prefix = -1;
  if (start > r || end < l) {
    return result;
  }
  if (start >= l && end <= r) {
    return tree[idx];
  }
  long long mid = (start + end) / 2;
  if (l > mid) {
    return query(2 * idx + 2, mid + 1, end, l, r);
  }
  if (r <= mid) {
    return query(2 * idx + 1, start, mid, l, r);
  }
  node left = query(2 * idx + 1, start, mid, l, r);
  node right = query(2 * idx + 2, mid + 1, end, l, r);
  result.sum = left.sum + right.sum;
  result.prefix = max(left.prefix, left.sum + right.prefix);
  return result;
}
void build2(long long idx, long long start, long long end) {
  if (start == end) {
    tree2[idx].sum = v[start];
    tree2[idx].prefix = v[start];
  } else {
    long long mid = (start + end) / 2;
    build2(2 * idx + 1, start, mid);
    build2(2 * idx + 2, mid + 1, end);
    tree2[idx].sum = tree2[2 * idx + 1].sum + tree2[2 * idx + 2].sum;
    tree2[idx].prefix = max(tree2[2 * idx + 1].prefix,
                            tree2[2 * idx + 1].sum + tree2[2 * idx + 2].prefix);
  }
}
node query2(long long idx, long long start, long long end, long long l,
            long long r) {
  node result;
  result.sum = result.prefix = -1;
  if (start > r || end < l) {
    return result;
  }
  if (start >= l && end <= r) {
    return tree2[idx];
  }
  long long mid = (start + end) / 2;
  if (l > mid) {
    return query2(2 * idx + 2, mid + 1, end, l, r);
  }
  if (r <= mid) {
    return query2(2 * idx + 1, start, mid, l, r);
  }
  node left = query2(2 * idx + 1, start, mid, l, r);
  node right = query2(2 * idx + 2, mid + 1, end, l, r);
  result.sum = left.sum + right.sum;
  result.prefix = max(left.prefix, left.sum + right.prefix);
  return result;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  long long te = 1;
  cin >> n >> te;
  a.read(n, false);
  b.read(n, false);
  for (int i = 0; i < n; ++i) {
    v[i] = a[i] - b[i];
    sum[i] = abs(v[i]);
    as[i] = v[i];
    if (i > 0) sum[i] += sum[i - 1];
    if (i > 0) as[i] += as[i - 1];
  }
  build(0, 0, n - 1);
  while (te--) {
    cin >> l >> r;
    --l;
    --r;
    if (v[l] > 0 || v[r] < 0) {
      cout << -1 << "\n";
      continue;
    }
    long long s = sum[r];
    if (l > 0) s -= sum[l - 1];
    long long zz = as[r];
    if (l > 0) zz -= as[l - 1];
    if (zz != 0) {
      cout << -1 << "\n";
      continue;
    }
    if (r - l + 1 == 2) {
      if (abs(v[l]) != abs(v[r])) {
        cout << -1 << "\n";
        continue;
      } else {
        cout << abs(v[l]) << "\n";
        continue;
      }
      continue;
    }
    if (query2(0, 0, n - 1, l, r).prefix != 0) {
      cout << -1 << "\n";
      continue;
    }
    cout << query(0, 0, n - 1, l, r).prefix << "\n";
    continue;
  }
}

### Prompt

Create a solution in Cpp for the following problem:

<image>

William has two arrays a and b, each consisting of n items.

For some segments l..r of these arrays William wants to know if it is possible to equalize the values of items in these segments using a balancing operation. Formally, the values are equalized if for each i from l to r holds a_i = b_i.

To perform a balancing operation an even number of indices must be selected, such that l ≤ pos_1 < pos_2 < ... < pos_k ≤ r. Next the items of array a at positions pos_1, pos_3, pos_5, ... get incremented by one and the items of array b at positions pos_2, pos_4, pos_6, ... get incremented by one.

William wants to find out if it is possible to equalize the values of elements in two arrays for each segment using some number of balancing operations, and what is the minimal number of operations required for that. Note that for each segment the operations are performed independently.

Input

The first line contains a two integers n and q (2 ≤ n ≤ 10^5, 1 ≤ q ≤ 10^5), the size of arrays a and b and the number of segments.

The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^9).

The third line contains n integers b_1, b_2, ..., b_n (0 ≤ b_i ≤ 10^9).

Each of the next q lines contains two integers l_i and r_i (1 ≤ l_i < r_i ≤ n), the edges of segments.

Output

For each segment output a single number — the minimal number of balancing operations needed or "-1" if it is impossible to equalize segments of arrays.

Example

Input


8 5
0 1 2 9 3 2 7 5
2 2 1 9 4 1 5 8
2 6
1 7
2 4
7 8
5 8


Output


1
3
1
-1
-1

Note

For the first segment from 2 to 6 you can do one operation with pos = [2, 3, 5, 6], after this operation the arrays will be: a = [0, 2, 2, 9, 4, 2, 7, 5], b = [2, 2, 2, 9, 4, 2, 5, 8]. Arrays are equal on a segment from 2 to 6 after this operation.

For the second segment from 1 to 7 you can do three following operations: 

  1. pos = [1, 3, 5, 6] 
  2. pos = [1, 7] 
  3. pos = [2, 7] 



After these operations, the arrays will be: a = [2, 2, 2, 9, 4, 2, 7, 5], b = [2, 2, 2, 9, 4, 2, 7, 8]. Arrays are equal on a segment from 1 to 7 after these operations.

For the third segment from 2 to 4 you can do one operation with pos = [2, 3], after the operation arrays will be: a = [0, 2, 2, 9, 3, 2, 7, 5], b = [2, 2, 2, 9, 4, 1, 5, 8]. Arrays are equal on a segment from 2 to 4 after this operation.

It is impossible to equalize the fourth and the fifth segment.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long good_rand() { return rand() * RAND_MAX + rand(); }
long long high_rand() {
  long long ran = rand() * RAND_MAX;
  ran *= RAND_MAX;
  ran += rand() * RAND_MAX + rand();
  return ran;
}
template <class A>
class myvector : public std::vector<A> {
 public:
  A &operator[](int pos) {
    if (pos < 0) pos = 0;
    while (this->size() <= pos) {
      this->push_back({});
    }
    return std::vector<A>::operator[](pos);
  }
  void print(bool b = false) {
    unsigned int si = this->size();
    if (b) std::cout << si << std::endl;
    for (unsigned int i = 0; i < si; ++i) {
      std::cout << this->operator[](i) << " ";
    }
  }
  void printendl(bool b = false) {
    print(b);
    std::cout << std::endl;
  }
  void good_random_shuffle() {
    unsigned int si = this->size();
    for (unsigned int i = 0; i < si - 1; ++i) {
      unsigned int j = good_rand() % (si - i);
      j += i;
      swap(this->operator[](i), this->operator[](j));
    }
  }
  template <class B>
  void read(B &n, bool b = false) {
    if (b) std::cin >> n;
    for (int i = 0; i < n; ++i) {
      std::cin >> this->operator[](i);
    }
  }
  void push_to(int pos, int val) {
    while (this->size() > pos) {
      int newval = this->operator[](pos);
      this->operator[](pos) = val;
      val = newval;
      ++pos;
    }
    this->operator[](pos) = val;
  }
};
template <class A>
class myqueue : public std::queue<A> {
 public:
  A front() const {
    if (this->empty()) return {};
    return std::queue<A>::front();
  }
  A top() const { return front(); }
  void pop() {
    if (this->empty()) return;
    std::queue<A>::pop();
  }
  A take() {
    A a = this->front();
    this->pop();
    return a;
  }
  void print(bool b = false) {
    while (!this->empty()) {
      std::cout << take() << " ";
    }
  }
  void printendl(bool b = false) {
    print(b);
    std::cout << std::endl;
  }
};
template <class A, class B = std::less<typename std::vector<A>::value_type>>
class mypriority_queue : public std::priority_queue<A, std::vector<A>, B> {
 public:
  A top() const {
    if (this->empty()) return {};
    return std::priority_queue<A, std::vector<A>, B>::top();
  }
  void pop() {
    if (this->empty()) return;
    std::priority_queue<A, std::vector<A>, B>::pop();
  }
  A take() {
    A a = this->top();
    this->pop();
    return a;
  }
  void print(bool b = false) {
    while (!this->empty()) {
      std::cout << take() << " ";
    }
  }
  void printendl(bool b = false) {
    print(b);
    std::cout << std::endl;
  }
};
class modll {
  static const long long mod = 998244353;
  long long modvalue = 0;

 public:
  modll() { this->modvalue = 0; }
  modll(int x) { this->modvalue = x % mod; }
  modll(long long x) { this->modvalue = x % mod; }
  modll(const modll &x) { this->modvalue = x.modvalue; }
  long long getmodvalue() const { return modvalue; }
  static long long modpow(long long z, long long u) {
    if (u == 0) return 1;
    if (u == 1) return z;
    if (u % 2 == 0) {
      long long sa = modpow(z, u / 2);
      return (sa * sa) % mod;
    }
    return (z * modpow(z, u - 1)) % mod;
  }
  static modll fastpow(long long z, long long u) {
    modll a = modpow(z, u);
    return a;
  }
  static modll fact(long long z) {
    modll a = 1;
    for (long long i = 2; i <= z; ++i) {
      a *= i;
    }
    return a;
  }
  static modll choose(long long n, long long k) {
    modll a = 1;
    for (long long i = n; n - i + 1 <= k; --i) {
      modll b = i;
      a = a * b;
    }
    for (long long i = 2; i <= k; ++i) {
      modll b = i;
      a = a / b;
    }
    return a;
  }
  long long rec() const { return modll::modpow(modvalue, mod - 2); }
  modll operator+(const modll &x) const {
    modll a;
    a.modvalue = (this->modvalue + x.modvalue) % mod;
    return a;
  }
  modll operator-(const modll &x) const {
    modll a;
    a.modvalue = (mod + this->modvalue - x.modvalue) % mod;
    return a;
  }
  modll operator*(const modll &x) const {
    modll a;
    a.modvalue = (this->modvalue * x.modvalue) % mod;
    return a;
  }
  modll operator/(const modll &x) const {
    modll a;
    if (x.modvalue == 0) return a;
    a.modvalue = (this->modvalue * x.rec()) % mod;
    return a;
  }
  template <class A>
  modll operator+(A x) const {
    if (x < 0) return this->operator-(-x);
    modll a;
    a.modvalue = (this->modvalue + x % mod) % mod;
    return a;
  }
  template <class A>
  modll operator-(A x) const {
    if (x < 0) return this->operator+(-x);
    modll a;
    a.modvalue = (this->modvalue - (x % mod) + mod) % mod;
    return a;
  }
  template <class A>
  modll operator*(A x) const {
    if (x < 0) {
      long long y = x / mod;
      y *= mod;
      y = x - y;
      x = y;
    }
    x %= mod;
    modll a;
    a.modvalue = (this->modvalue * x) % mod;
    return a;
  }
  template <class A>
  modll operator/(A x) const {
    if (x < 0) {
      long long y = x / mod;
      y *= mod;
      y = x - y;
      x = y;
    }
    x %= mod;
    modll a;
    if (x == 0) return a;
    modll b = x;
    a = *this / b;
    return a;
  }
  void operator=(modll x) { this->modvalue = x.modvalue; }
  template <class A>
  void operator=(A x) {
    this->modvalue = x % mod;
  }
  bool operator==(modll x) const { return (this->modvalue == x.modvalue); }
  template <class A>
  bool operator==(A x) const {
    return (this->modvalue == x);
  }
  bool operator<(modll x) const { return (this->modvalue < x.modvalue); }
  template <class A>
  bool operator<(A x) const {
    return (this->modvalue < x);
  }
  bool operator>(modll x) const { return (this->modvalue > x.modvalue); }
  template <class A>
  bool operator>(A x) {
    return (this->modvalue > x);
  }
  bool operator<=(modll x) const { return (this->modvalue <= x.modvalue); }
  template <class A>
  bool operator<=(A x) const {
    return (this->modvalue <= x);
  }
  bool operator>=(modll x) const { return (this->modvalue >= x.modvalue); }
  template <class A>
  bool operator>=(A x) const {
    return (this->modvalue >= x);
  }
  void operator+=(const modll &x) {
    this->modvalue += x.modvalue;
    this->modvalue %= mod;
  }
  template <class A>
  void operator+=(A x) {
    if (x < 0) this->operator+=(-1 * x);
    this->modvalue += x % mod;
    if (modvalue < 0) {
      this->modvalue *= -1;
      if (modvalue % mod == 0)
        modvalue = 0;
      else
        modvalue = mod - (modvalue % mod);
    }
    this->modvalue %= mod;
  }
  void operator-=(const modll &x) {
    this->modvalue -= x.modvalue;
    while (this->modvalue < 0) this->modvalue += mod;
    this->modvalue %= mod;
  }
  template <class A>
  void operator-=(A x) {
    if (x < 0) this->operator+=(-1 * x);
    this->modvalue -= x % mod;
    if (modvalue < 0) {
      this->modvalue *= -1;
      if (modvalue % mod == 0)
        modvalue = 0;
      else
        modvalue = mod - (modvalue % mod);
    }
    this->modvalue %= mod;
  }
  void operator*=(const modll &x) {
    this->modvalue *= x.modvalue;
    this->modvalue %= mod;
  }
  template <class A>
  void operator*=(A x) {
    bool neg = false;
    if (x < 0) {
      neg = true;
      x *= -1;
    }
    this->modvalue *= x % mod;
    if (modvalue < 0) {
      this->modvalue *= -1;
      if (modvalue % mod == 0)
        modvalue = 0;
      else
        modvalue = mod - (modvalue % mod);
    }
    this->modvalue %= mod;
    if (neg) {
      this->modvalue = mod - modvalue;
      this->modvalue %= mod;
    }
  }
  void operator/=(const modll &x) {
    if (x.modvalue == 0) {
      this->modvalue = 0;
      return;
    }
    this->modvalue = this->modvalue / x.modvalue;
    this->modvalue %= mod;
  }
  template <class A>
  void operator/=(A x) {
    bool neg = false;
    if (x < 0) {
      neg = true;
      x *= -1;
    }
    modll se = x % mod;
    this->operator/=(se);
    if (modvalue < 0) {
      this->modvalue *= -1;
      if (modvalue % mod == 0)
        modvalue = 0;
      else
        modvalue = mod - (modvalue % mod);
    }
    this->modvalue %= mod;
    if (neg) {
      this->modvalue = mod - modvalue;
      this->modvalue %= mod;
    }
  }
  modll operator++() {
    modvalue++;
    if (modvalue == mod) modvalue = 0;
  }
  modll operator--() {
    modvalue--;
    if (modvalue < 0) modvalue += mod;
  }
  void print() const { std::cout << this->modvalue; }
  void printspace() const { std::cout << this->modvalue << " "; }
  void printendl() const { std::cout << this->modvalue << std::endl; }
};
string yes = "YES\n";
string no = "NO\n";
myvector<long long> v;
myvector<long long> a;
myvector<long long> b;
long long n, m, k, l, r;
mypriority_queue<long long, std::greater<long long>> pq;
myqueue<long long> q;
set<long long> s;
long long sum[100005];
long long as[100005];
typedef struct node {
  long long sum;
  long long prefix;
} node;
node tree[4 * 100005];
node tree2[4 * 100005];
void build(long long idx, long long start, long long end) {
  if (start == end) {
    tree[idx].sum = v[start] * long long(-1);
    tree[idx].prefix = v[start] * long long(-1);
  } else {
    long long mid = (start + end) / 2;
    build(2 * idx + 1, start, mid);
    build(2 * idx + 2, mid + 1, end);
    tree[idx].sum = tree[2 * idx + 1].sum + tree[2 * idx + 2].sum;
    tree[idx].prefix = max(tree[2 * idx + 1].prefix,
                           tree[2 * idx + 1].sum + tree[2 * idx + 2].prefix);
  }
}
node query(long long idx, long long start, long long end, long long l,
           long long r) {
  node result;
  result.sum = result.prefix = -1;
  if (start > r || end < l) {
    return result;
  }
  if (start >= l && end <= r) {
    return tree[idx];
  }
  long long mid = (start + end) / 2;
  if (l > mid) {
    return query(2 * idx + 2, mid + 1, end, l, r);
  }
  if (r <= mid) {
    return query(2 * idx + 1, start, mid, l, r);
  }
  node left = query(2 * idx + 1, start, mid, l, r);
  node right = query(2 * idx + 2, mid + 1, end, l, r);
  result.sum = left.sum + right.sum;
  result.prefix = max(left.prefix, left.sum + right.prefix);
  return result;
}
void build2(long long idx, long long start, long long end) {
  if (start == end) {
    tree2[idx].sum = v[start];
    tree2[idx].prefix = v[start];
  } else {
    long long mid = (start + end) / 2;
    build2(2 * idx + 1, start, mid);
    build2(2 * idx + 2, mid + 1, end);
    tree2[idx].sum = tree2[2 * idx + 1].sum + tree2[2 * idx + 2].sum;
    tree2[idx].prefix = max(tree2[2 * idx + 1].prefix,
                            tree2[2 * idx + 1].sum + tree2[2 * idx + 2].prefix);
  }
}
node query2(long long idx, long long start, long long end, long long l,
            long long r) {
  node result;
  result.sum = result.prefix = -1;
  if (start > r || end < l) {
    return result;
  }
  if (start >= l && end <= r) {
    return tree2[idx];
  }
  long long mid = (start + end) / 2;
  if (l > mid) {
    return query2(2 * idx + 2, mid + 1, end, l, r);
  }
  if (r <= mid) {
    return query2(2 * idx + 1, start, mid, l, r);
  }
  node left = query2(2 * idx + 1, start, mid, l, r);
  node right = query2(2 * idx + 2, mid + 1, end, l, r);
  result.sum = left.sum + right.sum;
  result.prefix = max(left.prefix, left.sum + right.prefix);
  return result;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  long long te = 1;
  cin >> n >> te;
  a.read(n, false);
  b.read(n, false);
  for (int i = 0; i < n; ++i) {
    v[i] = a[i] - b[i];
    sum[i] = abs(v[i]);
    as[i] = v[i];
    if (i > 0) sum[i] += sum[i - 1];
    if (i > 0) as[i] += as[i - 1];
  }
  build(0, 0, n - 1);
  while (te--) {
    cin >> l >> r;
    --l;
    --r;
    if (v[l] > 0 || v[r] < 0) {
      cout << -1 << "\n";
      continue;
    }
    long long s = sum[r];
    if (l > 0) s -= sum[l - 1];
    long long zz = as[r];
    if (l > 0) zz -= as[l - 1];
    if (zz != 0) {
      cout << -1 << "\n";
      continue;
    }
    if (r - l + 1 == 2) {
      if (abs(v[l]) != abs(v[r])) {
        cout << -1 << "\n";
        continue;
      } else {
        cout << abs(v[l]) << "\n";
        continue;
      }
      continue;
    }
    if (query2(0, 0, n - 1, l, r).prefix != 0) {
      cout << -1 << "\n";
      continue;
    }
    cout << query(0, 0, n - 1, l, r).prefix << "\n";
    continue;
  }
}

```