description: <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.
solution: import java.util.*;
  import java.io.*;
  
  public class DeltixRound {
  
      ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////                                                                                                               /////////
  ////////                                                                                                               /////////
  ////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM         OOOOOO             SSSSSSS      EEEEEEEEEEEEE  /////////
  ////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMMMM      MMMMMM      OOO      OOO        SSSS   SSS     EEEEEEEEEEEEE  /////////
  ////////   HHHH        HHHH  EEEEE           MMMM MMM  MMM MMMM    OOO          OOO    SSSS       SSS   EEEEE          /////////
  ////////   HHHH        HHHH  EEEEE           MMMM  MMMMMM  MMMM   OOO            OOO   SSSS             EEEEE          /////////
  ////////   HHHH        HHHH  EEEEE           MMMM          MMMM  OOO              OOO   SSSSSSS         EEEEE          /////////
  ////////   HHHHHHHHHHHHHHHH  EEEEEEEEEEE     MMMM          MMMM  OOO              OOO      SSSSSS       EEEEEEEEEEE    /////////
  ////////   HHHHHHHHHHHHHHHH  EEEEEEEEEEE     MMMM          MMMM  OOO              OOO         SSSSSSS   EEEEEEEEEEE    /////////
  ////////   HHHH        HHHH  EEEEE           MMMM          MMMM   OOO            OOO              SSSS  EEEEE          /////////
  ////////   HHHH        HHHH  EEEEE           MMMM          MMMM    OOO          OOO     SSS       SSSS  EEEEE          /////////
  ////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM      OOO      OOO        SSS    SSSS    EEEEEEEEEEEEE  /////////
  ////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM         OOOOOO             SSSSSSS      EEEEEEEEEEEEE  /////////
  ////////                                                                                                               /////////
  ////////                                                                                                               /////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  
      public static void main(String[] args) throws IOException {
          Scanner sc = new Scanner(System.in);
          PrintWriter pw = new PrintWriter(System.out);
          int t = 1;
          while (t-- > 0) {
              int n = sc.nextInt();
              int q = sc.nextInt();
              int sz = 1;
  
              while (sz < n) sz <<= 1;
              long[] need = new long[sz + 1];
              int[] a = new int[sz + 1];
              int[] b = new int[sz + 1];
  
              for (int i = 1; i <= n; i++)
                  a[i] = sc.nextInt();
              for (int i = 1; i <= n; i++)
                  b[i] = sc.nextInt();
  
              for (int i = 1; i <= n; i++)
                  need[i] = b[i] - a[i];
  
              SegmentTree tree = new SegmentTree(need);
              while (q-- > 0) {
  
                  long[] cur = tree.query(sc.nextInt(), sc.nextInt());
  //                System.err.println(Arrays.toString(cur));
                  if (cur[0] == 0 && cur[1] == 0) {
                      pw.println(cur[2]);
                  } else pw.println(-1);
              }
  
          }
          pw.flush();
      }
  
      static class SegmentTree {        // 1-based DS, OOP
  
          int N;            //the number of elements in the array as a power of 2 (i.e. after padding)
          long[] array, sTree[];
  
          SegmentTree(long[] in) {
              array = in;
              N = in.length - 1;
              sTree = new long[N << 1][3];        //no. of nodes = 2*N - 1, we add one to cross out index zero
              build(1, 1, N);
          }
  
          void build(int node, int b, int e)    // O(n)
          {
              if (b == e)
                  sTree[node] = new long[]{array[b], Math.max(-array[b], 0), Math.max(array[b], 0)};
              else {
                  int mid = b + e >> 1;
                  build(node << 1, b, mid);
                  build(node << 1 | 1, mid + 1, e);
                  sTree[node] = merge(sTree[node << 1], sTree[node << 1 | 1]);
              }
          }
  
          long[] merge(long[] left, long[] right) {
              long[] res = new long[3];
              res[0] += left[0] + right[0];
  
              res[1] = Math.max(0, Math.max(left[1], -(left[0] - right[1])));
  
              res[2] = Math.max(0, Math.max(left[2], (left[0] + right[2])));
              return res;
          }
  
  
          long[] query(int i, int j) {
              return query(1, 1, N, i, j);
          }
  
          long[] query(int node, int b, int e, int i, int j)    // O(log n)
          {
              if (i > e || j < b)
                  return new long[]{0, 0, 0};
              if (b >= i && e <= j)
                  return sTree[node];
              int mid = b + e >> 1;
  
              long[] q1 = query(node << 1, b, mid, i, j);
              long[] q2 = query(node << 1 | 1, mid + 1, e, i, j);
              return merge(q1, q2);
  
          }
      }
  
      static int gcd(int a, int b) {
          if (a == 0)
              return b;
          return gcd(b % a, a);
      }
  
      static class Scanner {
          StringTokenizer st;
          BufferedReader br;
  
          public Scanner(FileReader r) {
              br = new BufferedReader(r);
          }
  
          public Scanner(InputStream s) {
              br = new BufferedReader(new InputStreamReader(s));
          }
  
          public String next() throws IOException {
              while (st == null || !st.hasMoreTokens())
                  st = new StringTokenizer(br.readLine());
              return st.nextToken();
          }
  
          public int[] nextIntArr(int n) throws IOException {
              int[] a = new int[n];
              for (int i = 0; i < n; i++) {
                  a[i] = nextInt();
              }
              return a;
          }
  
          public int nextInt() throws IOException {
              return Integer.parseInt(next());
          }
  
          public long nextLong() throws IOException {
              return Long.parseLong(next());
          }
  
          public String nextLine() throws IOException {
              return br.readLine();
          }
  
          public double nextDouble() throws IOException {
              String x = next();
              StringBuilder sb = new StringBuilder("0");
              double res = 0, f = 1;
              boolean dec = false, neg = false;
              int start = 0;
              if (x.charAt(0) == '-') {
                  neg = true;
                  start++;
              }
              for (int i = start; i < x.length(); i++)
                  if (x.charAt(i) == '.') {
                      res = Long.parseLong(sb.toString());
                      sb = new StringBuilder("0");
                      dec = true;
                  } else {
                      sb.append(x.charAt(i));
                      if (dec)
                          f *= 10;
                  }
              res += Long.parseLong(sb.toString()) / f;
              return res * (neg ? -1 : 1);
          }
  
          public boolean ready() throws IOException {
              return br.ready();
          }
      }
  
  }