#include <bits/stdc++.h>
using namespace std;
struct Comparator {
  bool operator()(const pair<long long, long long>& lhs,
                  const pair<long long, long long>& rhs) const {
    if (lhs.first == rhs.first) return lhs.second < rhs.second;
    return lhs.first < rhs.first;
  }
  bool operator()(long long a, long long b) const { return a > b; }
};
struct streeMin {
  long long n;
  vector<long long> tree;
  vector<long long> pushMem;
  const long long inf = 9999999999999999;
  streeMin(long long n) { tree.resize(4 * n); }
  void build(vector<long long>& arr, long long v = 0, long long l = 0,
             long long r = -1) {
    if (r == -1) r = arr.size() - 1;
    if (l == r) {
      tree[v] = arr[l];
      return;
    }
    long long mid = (l + r) / 2;
    build(arr, 2 * v + 1, l, mid);
    build(arr, 2 * v + 2, mid + 1, r);
    tree[v] = min(tree[2 * v + 1], tree[2 * v + 2]);
  }
  void push(long long v, long long l, long long r) {
    tree[2 * v + 1] += pushMem[v];
    tree[2 * v + 2] += pushMem[v];
    pushMem[2 * v + 1] += pushMem[v];
    pushMem[2 * v + 2] += pushMem[v];
    pushMem[v] = 0;
  }
  void change(long long l, long long r, long long val, long long v = 0,
              long long vL = 0, long long vR = -1) {
    if (vR == -1) vR = tree.size() / 4 - 1;
    if (vR < l || vL > r) return;
    if (vL >= l && vR <= r) {
      tree[v] += val;
      pushMem[v] += val;
      return;
    }
    long long mid = (vL + vR) / 2;
    change(l, r, val, 2 * v + 1, vL, mid);
    change(l, r, val, 2 * v + 2, mid + 1, vR);
    tree[v] = min(tree[2 * v + 1], tree[2 * v + 2]);
  }
  long long get(long long l, long long r, long long v = 0, long long vL = 0,
                long long vR = -1) {
    if (vR == -1) vR = tree.size() / 4 - 1;
    if (vR < l || vL > r) return inf;
    if (vL >= l && vR <= r) {
      return tree[v];
    }
    long long mid = (vL + vR) / 2;
    return min(get(l, r, 2 * v + 1, vL, mid),
               get(l, r, 2 * v + 2, mid + 1, vR));
  }
};
struct streeMax {
  long long n;
  vector<long long> tree;
  vector<long long> pushMem;
  const long long inf = 99999999999999999;
  streeMax(long long n) { tree.resize(4 * n); }
  void build(vector<long long>& arr, long long v = 0, long long l = 0,
             long long r = -1) {
    if (r == -1) r = arr.size() - 1;
    if (l == r) {
      tree[v] = arr[l];
      return;
    }
    long long mid = (l + r) / 2;
    build(arr, 2 * v + 1, l, mid);
    build(arr, 2 * v + 2, mid + 1, r);
    tree[v] = max(tree[2 * v + 1], tree[2 * v + 2]);
  }
  void push(long long v, long long l, long long r) {
    tree[2 * v + 1] += pushMem[v];
    tree[2 * v + 2] += pushMem[v];
    pushMem[2 * v + 1] += pushMem[v];
    pushMem[2 * v + 2] += pushMem[v];
    pushMem[v] = 0;
  }
  void change(long long l, long long r, long long val, long long v = 0,
              long long vL = 0, long long vR = -1) {
    if (vR == -1) vR = tree.size() / 4 - 1;
    if (vR < l || vL > r) return;
    if (vL >= l && vR <= r) {
      tree[v] += val;
      pushMem[v] += val;
      return;
    }
    long long mid = (vL + vR) / 2;
    change(l, r, val, 2 * v + 1, vL, mid);
    change(l, r, val, 2 * v + 2, mid + 1, vR);
    tree[v] = max(tree[2 * v + 1], tree[2 * v + 2]);
  }
  long long get(long long l, long long r, long long v = 0, long long vL = 0,
                long long vR = -1) {
    if (vR == -1) vR = tree.size() / 4 - 1;
    if (vR < l || vL > r) return -inf;
    if (vL >= l && vR <= r) {
      return tree[v];
    }
    long long mid = (vL + vR) / 2;
    return max(get(l, r, 2 * v + 1, vL, mid),
               get(l, r, 2 * v + 2, mid + 1, vR));
  }
};
void solve() {
  long long n, q;
  cin >> n >> q;
  streeMax sMax(n + 1);
  streeMin sMin(n + 1);
  vector<long long> arr(n);
  for (long long i = 0; i < n; i++) cin >> arr[i];
  vector<long long> sum(n + 1);
  sum[0] = 0;
  for (long long i = 0; i < n; i++) {
    long long t;
    cin >> t;
    sum[i + 1] = arr[i] - t + sum[i];
  }
  sMax.build(sum);
  sMin.build(sum);
  while (q--) {
    long long l, r;
    cin >> l >> r;
    l--, r--;
    if (sum[l] != sum[r + 1]) {
      cout << "-1\n";
      continue;
    }
    if (sMax.get(l, r) - sum[l] > 0) {
      cout << "-1\n";
      continue;
    }
    cout << sum[l] - sMin.get(l, r) << '\n';
  }
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  solve();
  return 0;
}

### 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;
struct Comparator {
  bool operator()(const pair<long long, long long>& lhs,
                  const pair<long long, long long>& rhs) const {
    if (lhs.first == rhs.first) return lhs.second < rhs.second;
    return lhs.first < rhs.first;
  }
  bool operator()(long long a, long long b) const { return a > b; }
};
struct streeMin {
  long long n;
  vector<long long> tree;
  vector<long long> pushMem;
  const long long inf = 9999999999999999;
  streeMin(long long n) { tree.resize(4 * n); }
  void build(vector<long long>& arr, long long v = 0, long long l = 0,
             long long r = -1) {
    if (r == -1) r = arr.size() - 1;
    if (l == r) {
      tree[v] = arr[l];
      return;
    }
    long long mid = (l + r) / 2;
    build(arr, 2 * v + 1, l, mid);
    build(arr, 2 * v + 2, mid + 1, r);
    tree[v] = min(tree[2 * v + 1], tree[2 * v + 2]);
  }
  void push(long long v, long long l, long long r) {
    tree[2 * v + 1] += pushMem[v];
    tree[2 * v + 2] += pushMem[v];
    pushMem[2 * v + 1] += pushMem[v];
    pushMem[2 * v + 2] += pushMem[v];
    pushMem[v] = 0;
  }
  void change(long long l, long long r, long long val, long long v = 0,
              long long vL = 0, long long vR = -1) {
    if (vR == -1) vR = tree.size() / 4 - 1;
    if (vR < l || vL > r) return;
    if (vL >= l && vR <= r) {
      tree[v] += val;
      pushMem[v] += val;
      return;
    }
    long long mid = (vL + vR) / 2;
    change(l, r, val, 2 * v + 1, vL, mid);
    change(l, r, val, 2 * v + 2, mid + 1, vR);
    tree[v] = min(tree[2 * v + 1], tree[2 * v + 2]);
  }
  long long get(long long l, long long r, long long v = 0, long long vL = 0,
                long long vR = -1) {
    if (vR == -1) vR = tree.size() / 4 - 1;
    if (vR < l || vL > r) return inf;
    if (vL >= l && vR <= r) {
      return tree[v];
    }
    long long mid = (vL + vR) / 2;
    return min(get(l, r, 2 * v + 1, vL, mid),
               get(l, r, 2 * v + 2, mid + 1, vR));
  }
};
struct streeMax {
  long long n;
  vector<long long> tree;
  vector<long long> pushMem;
  const long long inf = 99999999999999999;
  streeMax(long long n) { tree.resize(4 * n); }
  void build(vector<long long>& arr, long long v = 0, long long l = 0,
             long long r = -1) {
    if (r == -1) r = arr.size() - 1;
    if (l == r) {
      tree[v] = arr[l];
      return;
    }
    long long mid = (l + r) / 2;
    build(arr, 2 * v + 1, l, mid);
    build(arr, 2 * v + 2, mid + 1, r);
    tree[v] = max(tree[2 * v + 1], tree[2 * v + 2]);
  }
  void push(long long v, long long l, long long r) {
    tree[2 * v + 1] += pushMem[v];
    tree[2 * v + 2] += pushMem[v];
    pushMem[2 * v + 1] += pushMem[v];
    pushMem[2 * v + 2] += pushMem[v];
    pushMem[v] = 0;
  }
  void change(long long l, long long r, long long val, long long v = 0,
              long long vL = 0, long long vR = -1) {
    if (vR == -1) vR = tree.size() / 4 - 1;
    if (vR < l || vL > r) return;
    if (vL >= l && vR <= r) {
      tree[v] += val;
      pushMem[v] += val;
      return;
    }
    long long mid = (vL + vR) / 2;
    change(l, r, val, 2 * v + 1, vL, mid);
    change(l, r, val, 2 * v + 2, mid + 1, vR);
    tree[v] = max(tree[2 * v + 1], tree[2 * v + 2]);
  }
  long long get(long long l, long long r, long long v = 0, long long vL = 0,
                long long vR = -1) {
    if (vR == -1) vR = tree.size() / 4 - 1;
    if (vR < l || vL > r) return -inf;
    if (vL >= l && vR <= r) {
      return tree[v];
    }
    long long mid = (vL + vR) / 2;
    return max(get(l, r, 2 * v + 1, vL, mid),
               get(l, r, 2 * v + 2, mid + 1, vR));
  }
};
void solve() {
  long long n, q;
  cin >> n >> q;
  streeMax sMax(n + 1);
  streeMin sMin(n + 1);
  vector<long long> arr(n);
  for (long long i = 0; i < n; i++) cin >> arr[i];
  vector<long long> sum(n + 1);
  sum[0] = 0;
  for (long long i = 0; i < n; i++) {
    long long t;
    cin >> t;
    sum[i + 1] = arr[i] - t + sum[i];
  }
  sMax.build(sum);
  sMin.build(sum);
  while (q--) {
    long long l, r;
    cin >> l >> r;
    l--, r--;
    if (sum[l] != sum[r + 1]) {
      cout << "-1\n";
      continue;
    }
    if (sMax.get(l, r) - sum[l] > 0) {
      cout << "-1\n";
      continue;
    }
    cout << sum[l] - sMin.get(l, r) << '\n';
  }
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  solve();
  return 0;
}

```