#include <bits/stdc++.h>
using namespace std;
void FAST_IO(string filein = "", string fileout = "", string fileerr = "") {
  if (fopen(filein.c_str(), "r")) {
    freopen(filein.c_str(), "r", stdin);
    freopen(fileout.c_str(), "w", stdout);
  }
  cin.tie(0), cout.tie(0)->sync_with_stdio(0);
}
void Hollwo_Pelw();
signed main() {
  FAST_IO("hollwo_pelw.inp", "hollwo_pelw.out");
  int testcases = 1;
  for (int test = 1; test <= testcases; test++) {
    Hollwo_Pelw();
  }
  return 0;
}
const int N = 1e5 + 5;
int n, q, a[N], lg[N];
int64_t pre[N], stmax[N][18], stmin[N][18];
inline int64_t query_max(int l, int r) {
  int j = lg[r - l + 1];
  return max(stmax[l][j], stmax[r - (1 << j) + 1][j]);
}
inline int64_t query_min(int l, int r) {
  int j = lg[r - l + 1];
  return min(stmin[l][j], stmin[r - (1 << j) + 1][j]);
}
void Hollwo_Pelw() {
  cin >> n >> q, lg[0] = -1;
  for (int i = 1, x; i <= n; i++) cin >> x, a[i] += x;
  for (int i = 1, x; i <= n; i++) cin >> x, a[i] -= x;
  for (int i = 1; i <= n; i++)
    pre[i] = pre[i - 1] + a[i], lg[i] = lg[i >> 1] + 1;
  for (int i = 1; i <= n; i++) stmin[i][0] = stmax[i][0] = pre[i];
  for (int j = 1; j < 18; j++)
    for (int i = 1; i + (1 << j) <= n + 1; i++) {
      stmax[i][j] = max(stmax[i][j - 1], stmax[i + (1 << j - 1)][j - 1]);
      stmin[i][j] = min(stmin[i][j - 1], stmin[i + (1 << j - 1)][j - 1]);
    }
  for (int l, r; q--;) {
    cin >> l >> r;
    cout << (pre[r] != pre[l - 1] || query_max(l, r) > pre[l - 1]
                 ? -1
                 : pre[l - 1] - query_min(l, r))
         << '\n';
  }
}
